I’m using: Ben Crokers Session Variables plugin, to remember a sinle integer, for use elsewhere in te site in an SQL query.
I thought I’d make life easy for the person after me and create a plug in that does all we need..
To that end, I’m having probs…
I’ve created a plugin called: hearstcalquery It has an SQL query that calls the DB and gets data relating to the parent brand, which is also the variable stored in the session tag.
Within my plug in I’ve called the TMPL variable and echoed it within my SQL query:
function hearstcalquery($str = '')
{
global $DB;
global $TMPL;
$parameter = $TMPL->fetch_param('parentBrand');
$query = $DB->query("
SELECT
rels.rel_parent_id as ParentCat
, rels.rel_child_id as ChildCat
, titles.title
, dataTable.field_id_61 as summary
, dataTable.field_id_60 as image
, titles.entry_date as entryDate
, weblog.weblog_id as weblogId
FROM exp_weblog_titles as titles
JOIN exp_relationships as rels on
rels.rel_parent_id = titles.entry_id
JOIN exp_weblog_data as dataTable on
dataTable.entry_id = titles.entry_id
JOIN exp_weblogs as weblog on
weblog.weblog_id = titles.weblog_id
WHERE rels.rel_child_id = " . $parameter . "
AND weblog.weblog_id = 10");
foreach($query->result as $row)
{
$this->return_data .= $row['entryDate'];
$this->return_data .= "
";
}
and my template is simply:
{exp:hearstcalquery parentBrand="{exp:session_variables:get name="parentBrand"}"}
{/exp:hearstcalquery}
it works fine if I hardcode the parentBrand, but not if I use thwe session..
So, are plug ins able to talk to each other? Any ideas for a fix for this?
Hiya,
Plugins definitely can talk to each other but you may be experiencing a slight parse order problem with this one. You could try this :
{exp:hearstcalquery parentBrand="{exp:session_variables:get name="parentBrand" parse="inward"}"}
{/exp:hearstcalquery}
The parse=”inward” bit should tell the Session Variables plugin to go first and then your own plugin. If that doesn’t work then try the parse=”inward” parameter on your plugin instead. Pretty sure it will need to go on the Session Variables plugin first although I have flu at the moment so might be mis-reading what you are doing.
Hope that helps a bit though.
Best wishes,
Mark
Ah, that didn’t work, but I’ve got round it with a few $_GET calls in my ajax..
Anyhoo.. I am wondering how I can simply output each variable from teh database: entryDate image summary etc
simply as {entryDate} {image} {summary}
the tutorial says $this->return_data but if I try and add $this->return_data[‘entryDate’] I get an error…
How can I call specific outputs from my plugin, to my template?
oooh, I founf this:
foreach($query->result as $row)
{
$tagdata = $TMPL->tagdata;
foreach ($TMPL->var_single as $key => $val)
{
if (isset($row[$val]))
{
$tagdata = $TMPL->swap_var_single($val, $row[$val], $tagdata);
}
}
$this->return_data .= $tagdata;
}
and it seems to be working!
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.