Jump to content

[SOLVED] Parsing issue with template?


Solarpitch

Recommended Posts

Hey guys,

 

I have this section of a template and I'm trying to call the get_products() function to display the results. I'm not sure if that whole if statement parsing is correct. I know the function above it is right as I'm returning the values from a function. But with the get_products() function noting is being returned.

 

You can see where I have $categories->content .= to connect the string again after the php, I'm not sure if this is correct.

 

<?php

        $category = 1;
        $sub_category = 22;

$categories = new page();
$categories->content = "

<div id='range_header'>Ranges</div>
<div id='range_menu'>
<ul>
".get_menu($category)."
</ul>
</div>
</div>

<div id='banner'><img src='designs/banner_bona.png' alt='Bona'></div>

<div id='content_top'>Bona</div>

<div id='results'>";

if(isset($sub_category)){ get_products($sub_category); }

$categories->content .= "</div>

<div class='options_box'>
<a href=''>Enquire about this product</a><br />
<a href=''>Add to Favorites</a>
</div>


</div>


";

?>

Link to comment
https://forums.phpfreaks.com/topic/129625-solved-parsing-issue-with-template/
Share on other sites

Well, if something IS being returned from that function, the code you have will do nothing with it.

 

Are the results of that function supposed to be added to $categories->content

 

if(isset($sub_category)){ $categories->content .= get_products($sub_category); }

For example this works perfect... but it wont work with the whole if statement.

 

<?php

.....

<div id='content_top'>Bona</div>

<div id='results'>".

get_products($sub_category)

."</div>

<div class='options_box'>
<a href=''>Enquire about this product</a><br />
<a href=''>Add to Favorites</a>
</div>


</div>

.....

?>

Did you try the line of code I posted? The way you had it previously you were not using the return values of the function - you were simply calling the function and the results were being thrown away.

 

The example you just posted appear to be that the function is called within an echo statemetn so the results would be echo'd.

 

Example:

function output ()
{
  return "Hello World!";
}

echo output();
//Result: Hello World

output();
//Result: --NOTHING--

 

use the line of code I posted in my first response and I think it will work how you want it.

Hey,

 

actually.. your code worked fine... thanks.

 

<?php

.....

<div id='range_header'>Engineered Range</div>
<div id='range_menu'>

";

foreach ($category as $arr) { $engineered_flooring->content .= get_menu($arr); }

$engineered_flooring->content .= "

</div>
</div>

<div id='banner'><img src='designs/banner_bona.png' alt='Bona'></div>

......

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.