Maths directly in Template

Discuss PivotX 2.0.x themes here, and view themes that are available for download.

Maths directly in Template

Postby Specis » Wed Feb 10, 2010 10:00 am

I'm working a theme for my personal blog. While updating from Pivot 1 to PivotX, I decided I should spruce up the old design. But I've encountered a slight problem.

See I'm not looking for each entry on the main page to look the same, I want the design to switch as it goes down the page. Which I have managed to achieve by adding a mod value to the template system in module_parser.php. Its pretty basic just returns the remainder of the current entry divided by how many entry designs I have currently which is 4.

So within the front-page template file I can put [[ include file="specis/bubble_entry_$mod.html" ]] within the subweblog section and this produces the expected result for me.

I was just wondering if the template system allows an easier way to do this kind of thing without resorting to adding additional code to the parser system. Because i just know the first update I'll forget that I edited that file and go ahead and blindly replace it.
Specis
 
Posts: 8
Joined: Wed Feb 10, 2010 9:37 am
Location: Glasgow, Scotland

Re: Maths directly in Template

Postby hansfn » Wed Feb 10, 2010 1:24 pm

Yes, you should never modify the core files. Anyway, you can easily set $mod in the template itself (inside the subweblog block):

Code: Select all
[[ assign var=mod value=`$counter%4` ]]
hansfn
Developer
 
Posts: 3282
Joined: Sun Nov 25, 2007 7:48 pm
Location: Molde, Norway

Re: Maths directly in Template

Postby Specis » Wed Feb 10, 2010 10:53 pm

Thanks! i was trying something similar to that, but it kept throwing errors.

Not to worry, Up and running now. And no edits to the core files.
Specis
 
Posts: 8
Joined: Wed Feb 10, 2010 9:37 am
Location: Glasgow, Scotland

Re: Maths directly in Template

Postby rabbeltje » Thu Feb 11, 2010 7:39 am

so, just out of curiosity, where in a template would i add this code? i tried to give the entry-div a class with this code, but that didn't work...
User avatar
rabbeltje
 
Posts: 358
Joined: Mon Aug 25, 2008 11:54 am
Location: Neerbeek, The Netherlands

Re: Maths directly in Template

Postby hansfn » Thu Feb 11, 2010 8:04 am

Code: Select all
<!-- begin of weblog 'standard' -->
[[ subweblog name="standard" ]][[ literal ]]

[[ assign var=mod value=`$counter%4` ]]
    <!-- entry '[[title]]' -->
    <div class="entry design[[ $mod ]]">
....
hansfn
Developer
 
Posts: 3282
Joined: Sun Nov 25, 2007 7:48 pm
Location: Molde, Norway

Re: Maths directly in Template

Postby rabbeltje » Thu Feb 11, 2010 8:11 am

thanks! i wouldn't have figured that out myself!
User avatar
rabbeltje
 
Posts: 358
Joined: Mon Aug 25, 2008 11:54 am
Location: Neerbeek, The Netherlands


Return to 2.x Themes

Who is online

Users browsing this forum: No registered users and 3 guests

cron