Skinning and designing Serendipity (CSS, HTML, Smarty)
reinhardl
Regular
Posts: 258 Joined: Wed Jun 20, 2007 8:54 am
Location: Germany
Post
by reinhardl » Mon Feb 21, 2011 9:43 am
Hi,
I am still working on a template, it´s nearly finished but I have a problem
config.inc
Code: Select all
$twocolcats= array();
for ($i = 0; $i < $template_loaded_config['two_col_cats']; $i++) {
$twocolcats[] = array(
'anzahl' => $template_loaded_config['twocolcat' . $i . 'text'],
'cat' => $template_loaded_config['twocolcat' . $i . 'cat'],
'kat' => $template_loaded_config['twocolcat' . $i . 'cat']
);
$template_config[] = array(
'var' => 'twocolcat' . $i . 'twocolcat_info',
'type' => 'content',
'default' => '<b><p style="color:#FFFFFF; background-color: orange">'. TWOCOLCAT_TITLE . ' #' . $i .'</p></b>' ,
);
$template_config[] = array(
'var' => 'twocolcat' . $i . 'text',
'name' => TWO_COL_ENTRIES . ' #' . $i,
'type' => 'string',
'default' => '2'
);
$template_config[] = array(
'var' => 'twocolcat' . $i . 'cat',
'name' => TWO_COL_CAT . ' #' . $i,
'type' => 'select',
'default' => '#',
'select_values' => $catsel,
);
}
$serendipity['smarty']->assign_by_ref('twocolcats', $twocolcats);
this fetch will work
index.tpl
Code: Select all
{foreach from=$twocolcats item="twocolcat" name=catlist}
{serendipity_fetchPrintEntries category= $twocolcat.cat full=true fetchDrafts=false noSticky=true limit="0,2" template="entries_2Cols.tpl"}
{/foreach}
and this fetch will NOT work:
( want to replace
limit="0,2" with
limit="0,$twocolcat.anzahl"
Code: Select all
{foreach from=$twocolcats item="twocolcat" name=catlist}
{serendipity_fetchPrintEntries category= $twocolcat.cat full=true fetchDrafts=false noSticky=true limit="0,$twocolcat.anzahl" template="entries_2Cols.tpl"}
{/foreach}
I suspect a syntax error
Any idea ?
Thanks
Timbalu
Regular
Posts: 4598 Joined: Sun May 02, 2004 3:04 pm
Post
by Timbalu » Mon Feb 21, 2011 10:06 am
Are you sure $twocolcat.anzahl is just a int? It does not look like it.
It looks like the right syntax, beside the whitespace, but did you try "0,{$twocolcat.anzahl}" else?
reinhardl
Regular
Posts: 258 Joined: Wed Jun 20, 2007 8:54 am
Location: Germany
Post
by reinhardl » Mon Feb 21, 2011 10:15 am
Timbalu wrote: .. did you try "0,{$twocolcat.anzahl}" else?
did not work
Timbalu
Regular
Posts: 4598 Joined: Sun May 02, 2004 3:04 pm
Post
by Timbalu » Mon Feb 21, 2011 10:27 am
Timbalu wrote: Are you sure $twocolcat.anzahl is just a int? It does not look like it.
What does a plain {$twocolcat.anzahl} inside your tpl, not inside the hook, say?
reinhardl
Regular
Posts: 258 Joined: Wed Jun 20, 2007 8:54 am
Location: Germany
Post
by reinhardl » Mon Feb 21, 2011 11:25 am
Code: Select all
{foreach from=$twocolcats item="twocolcat" name=catlist}
{assign var="test" value=$twocolcat.anzahl}
{assign var="test2" value=0,$test}
{serendipity_fetchPrintEntries category= $twocolcat.cat full=true fetchDrafts=false noSticky=true limit=$test2 template="entries_2Cols.tpl"}
{/foreach}
this will work now, but it is dirty code or?
Timbalu
Regular
Posts: 4598 Joined: Sun May 02, 2004 3:04 pm
Post
by Timbalu » Mon Feb 21, 2011 5:10 pm
Yes that looks pretty dirty...., but maybe its part of the hook that you can't pass 2 vars to an item
I think, you could reduce your code to
Code: Select all
{assign var="limit" value='0,$twocolcat.anzahl'}
{serendipity_fetchPrintEntries category=$twocolcat.cat full=true fetchDrafts=false noSticky=true limit=$limit template="entries_2Cols.tpl"}
or do something like
Code: Select all
'anzahl' => "0,".$template_loaded_config['twocolcat' . $i . 'text'],
in the array creating php file
Timbalu
Regular
Posts: 4598 Joined: Sun May 02, 2004 3:04 pm
Post
by Timbalu » Sat Feb 26, 2011 3:48 pm
I just remembered how to solve your original problem just a little more elegant, I think,
adding this to future questions:
In
Smarty 2 you can do
Code: Select all
{serendipity_fetchPrintEntries category=$twocolcat.cat full=true fetchDrafts=false noSticky=true limit="0,`$twocolcat.anzahl`" template="entries_2Cols.tpl"}
- note the backticks `
In upcoming
Smarty 3 you can also do
Code: Select all
{serendipity_fetchPrintEntries category=$twocolcat.cat full=true fetchDrafts=false noSticky=true limit="0,{$twocolcat.anzahl}" template="entries_2Cols.tpl"}
which will be a bit more intuitive to smartify expressions like this in future.