1

How can i convert the following code to EE Tags?

<?php 
if($_GET['rel']!='tab'){
    include 'header.php';
}
?>

I've used this with enabling the template to PHP, but i get the following error.

A PHP Error was encountered

Severity: Notice

Message: Undefined index: del

Filename: libraries/Functions.php(683) : eval()'d code

Line Number: 5

Thanks

2

There are a handful of addons that convert $_GET and $_POST variables to EE variables. This search might get you started. My favorite is Mo’ Variables, which converts them to global variables (of the early-parsed sort) like {get:rel}.

As for including, I'm not sure what your header.php file contains, but if it's more template code you could use an embedded template. Make a template group (say, embeds) and a template (header):

{if get:rel != 'tab'}
  {embed='embeds/header'}
{/if} 

If you do directly include the PHP file, make sure header.php doesn't use echo as that will result in PHP errors.

1

If your going to pull in GET values you should scrub it: $this->EE->input->get('rel', TRUE); ref http://ellislab.com/expressionengine/user-guide/development/usage/input.html

if ($this->EE->input->get('rel', TRUE) != 'tab'){ echo "{embed=\"site/header\"}"; }

With php parsed on input. If this is in a template the EE super global is already loaded. ( $this->EE =& get_instance();)

0

Two things:

  1. Your error message says Undefined index: del and your code example references $_GET['rel'] -- There's no typo at play here, is there?

  2. Try this?

Set PHP to run on Input.

<?php 
if($_GET['rel']!='tab'){
?>
<embed="template_group/header_template"> // With PHP enabled if you need
<?
}
?>
0

As far as I know the $_GET and $_POST variables (among others) are not available in templates. To accomplish something like this you could use url segments. So in you're example you may have a link like this: domain.com?rel=tab. Instead you may be able to do this: domain.com/tab. Then in your template (no PHP required) you can do this:

{if segment_1 == "tab"}
    {embed="site/header"}
{/if}

Where site/header is a template containing whatever code is in header.php. Note that the /tab could be any segment and change the conditional accordingly. I realize using segments instead of GET parameters may not always work, but this is how I have gotten around this problem myself a few times.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.