Jump to content

Correct variable use


daveyah2002
Go to solution Solved by daveyah2002,

Recommended Posts

Hi,

 

just joined today.

I am using a variable to chose a template dependent on when the user is logged in it shows a search box or not if they haven't. As a php beginner I just want to know if this is the correct method or should I be declaring 'template' somewhere specific.

It is only used in this one file.

 

I hope I've used the code tags correctly...

 

 
<php?
 
include_once("login_status.php")
 
 
If(user_login==true){
$template="template_top.php"
 ...web page with search box
}else{
...web page without search box
$template="template_top_NoSearch.php"
}
?>
 
 
 
<html>
<?php include_once($template); ?>
</html>
 

Link to comment
Share on other sites

Rather than have two templates one with a searchbox and the other without. Instead have one template for your sites over all layout. You then extract elements from that template into smaller template files which you only include when you need them. Ie in your templare file you have something like this

<html>
<head>
    <title>Site Title</title>
    ... etc
</head>
<body>

   ...

    <?php
    // if user logged in include the searchbar template
    if($user_login) include 'searchbar.php';
    ?>

   ...

  
<body>
</html>

Searchbar.php will only contain the HTML for your searchbar. The searchbar will only be shown if $user_login is true.

Link to comment
Share on other sites

Hi

 

Thanks for the reply,

 

I did think about that but I got the impression that as it's a form search box and part of the template for the top of the page then I would need to exclude individual form elements.

I could be wrong.  To me that was more hassle than it's worth and easier to reproduce the top template with and without the form.

I will have another look at it though.

 

Many thanks.

 

Thanks.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.