Hi, I have a function that sits outside of the constructor for the class.
function purchase()
{
global $IN, $PREFS, $DB, $TMPL, $FNS;
$this->return_data = '<form method="POST" action="purchase">'
.'<input type="hidden" name="entry_id" value="'.$TMPL->fetch_param('entry_id').'">'
.'<input type="hidden" name="return_url" value="'.$_SERVER['PHP_SELF'].'">'
.'<input type="text" size="2" name="quantity" value="1">'
.str_replace('{entry}',$TMPL->fetch_param('entry_id'), $TMPL->tagdata)
.'<input type="submit" value="Add to cart">
</form>';
}[/code]
I am calling it like this in my template.
[code]
{exp:commerce:purchase entry_id="5"}
{entry}
{/exp:commerce:purchase}
I get no output, but if I throw it back up in the constructor it renders to the template just fine.
Am I missing something simple here?
I am by no means an expert here - but I don’t think what is happening is what you think. {entry} isn’t getting replaced by anything in either case I don’t believe - to do that you need to use $TMPL->swap_var_single.
Check out this page (if you haven’t already):
http://expressionengine.com/docs/development/usage/template.html
And look specifically at Data Within Tag Pairs.
I have changed to the following:
{exp:commerce:purchase entry_id="5"}
{buy_button}
{/exp:commerce:purchase}
function purchase()
{
global $IN, $PREFS, $DB, $TMPL, $FNS;
$buy_button = '<form method="POST" action="purchase">'
.'<input type="hidden" name="entry_id" value="'.$TMPL->fetch_param('entry_id').'">'
.'<input type="hidden" name="return_url" value="'.$_SERVER['PHP_SELF'].'">'
.'<input type="text" size="2" name="quantity" value="1">'
.str_replace('{entry}',$TMPL->fetch_param('entry_id'), $TMPL->tagdata)
.'<input type="submit" value="Add to cart">
</form>';
$this->return_data = $TMPL->swap_var_single('{buy_button}', $buy_button, $TMPL->tagdata);
}
Still no output to the template though.
Another weird thing.
(0.119531) Calling Class/Method: Commerce/purchase (0.119670) -> Class Called: Commerce (0.119804) -> Method Called: commerce (0.119821) -> Data Returned (0.119920) - End Tag Processing -
Shouldn’t the “Method Called” be “purchase” based on my tag format.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.