1

How can I use a PhpFox variable with substr? When I use the variable in a {php} {/php} it's giving me undefined variable:

Example:

I have the variable:{$aFeed.feed_image_onclick}

Now I want to substr this variable in my template file:

{php} substr($aFeed.feed_image_onclick, 1, 3);{/php} 

But is it even possible to use class generated variable in the {php} tag?

Thanks!

Irfan
  • 4,301
  • 6
  • 29
  • 46

3 Answers3

0

Avoid using {php}{/php} blocks, that's the hacky way of doing things. Instead, do all the processing in your php controller (/module/my_module/include/component/controller/my_controller.class.php), including substrings, calls to service functions,...etc. Then assign to a template variable:

$this->template()->assign(array('some_var' => $my_thing));

When you use {php} blocks in the template you are coding in something that will be compiled later on, you can use class variables but its an awful way of doing it (look at one of the cached files and you'll find the all the variables used)

Purefan
  • 1,498
  • 24
  • 44
0

Yes you can. The variable is called

$this->_aVars['your_variable']

But if you are inside of a loop then you have to do it like so

{foreach from=$aPage key=i item=page}
   {php} echo $this->_aVars['page']; {/php}
{/foreach}

To answer your question, you have to do it like this:

<span class="values">{php} echo substr($this->_aVars['aFeed']['feed_image_onclick'],1,3); {/php}</span>

PS Just my 2 cent: If there is a possibility to do so, developers will use it - weather it is "hacky" or not.

KIC
  • 5,887
  • 7
  • 58
  • 98
0

Try this

    {$aFeed.feed_image_onclick|substr:1:3}

In Phpfox template before | is the first parameter of function and after | is the name of function if you want to pass more than one parameter to a function then simply add : after the function or parameter and add the parameter like i added in this code. This code prints the result to the template.

keshu_vats
  • 452
  • 6
  • 45