Problems, need help? Have a tip or advice? Post it here.
2 posts Page 1 of 1
Hey there, Couch-people :)

I am currently trying to somehow store the current year in a variable that i can re-use for a <cms:if> condition, to display an "active" attribute in an anchor tag.

I tried creating a global value using the cms:php tag, but i can't seem to use it in the if condition.. Is there any suggested best practise?

This is what i tried:

Code: Select all
 <cms:editable
name='year'
label='Year'
desc='enter year'
type='text' />

<cms:php>
  global $curyear;
   $curyear = echo date('Y');
</cms:php>

<cms:if year = curyear >
class="active"
</cms:if>



I am not a PHP expert, so i am sure i am missing something here - a less clumsy approach would also be greatly appreciated! :)

Thanks in advance!

Kind regards

Sundance
You can set and get variables with couch code. Couch also has a date tag.
Code: Select all
<cms:set curyear = "<cms:date format='Y' />" 'global' />
<cms:if year == curyear>
class="active"
</cms:if>

Alternatively,
Code: Select all
<cms:if year == "<cms:date format='Y' />" > class="active"</cms:if>

http://docs.couchcms.com/tags-reference/set.html
http://docs.couchcms.com/tags-reference/date.html

http://docs.couchcms.com/concepts/variables.html
2 posts Page 1 of 1

Who is online

In total there are 5 users online :: 1 registered, 0 hidden and 4 guests
(based on users active over the past 5 minutes)

Users browsing this forum: Google [Bot] and 4 guests