Forum for discussing general topics related to Couch.
3 posts Page 1 of 1
Hey all,

Firstly, just started using this (I've been a WordPress and Expression Engine hardcore user for the last 5 years) and I am so impressed by the balance of simplicity and agility. Bravo devs. Bravo.

Now, coming from my background and "methods" I wonder am I asking too much / pushing to hard with what I am trying to achieve in the, as I count, 8th hour of using this CMS.

Ok, so I love the idea of "Globals dot php" great way of setting up what I would refer to as "snippets" in EE, so handy for copyright notices, footer text etc.

So basically I am using a single globals file to host webmaster tools ID, analytics id etc along with some address jazz.

Now, setup and output is so easy, love it, however, what if I want to conditional check for values on global "get_custom_field"

Basically I have this as a simple starter global:

Code: Select all
<?php require_once( 'couch/cms.php' ); ?>
<cms:template name='globals' title='Globals' executable='0'>

<cms:editable name='call_to_action_bar' title='Call to Action Bar' type='richtext' />

<cms:editable name='company_address' title='Company Address' type='text' />
<cms:editable name='company_tel' title='Company Telephone' type='text' />
<cms:editable name='company_fax' title='Company Fax' type='text' />
<cms:editable name='company_email' title='Company Email' type='text' />
<cms:editable name='company_web' title='Company Web' type='text' />

</cms:template>

<?php COUCH::invoke(); ?>



How can / do (is it even possible) prefix outputs in my footer if the field exists, for example:

Code: Select all
<footer>
<cms:if get_custom_field 'company_tel' !="">
Tel: <cms:get_custom_field 'company_tel' masterpage='globals.php' /><br />
</cms:if>
</footer>


These little "ifs" would be very handy for prefixing text / icons (i.e. bootsrap glyphs or font awesome <i class=""> stuff).

Maybe someone can shed some light - if so thanks so much.
Hi Patrick,

Welcome to our forums :)

I am glad Couch did not disappoint you, especially considering that you are using a colossal like ExpressionEngine as the benchmark.

Replying to your query -
Yes, it is indeed possible to use cms:if to conditionally output the global values.

Couch has a concept that, IMHO, is not found in other CMSes - you can nest tags in a manner that the output of one tag becomes the input for another tag's parameter. Let me explain -
as you know the following unconditionally outputs whatever value is found (could be blank) in a particular field
<cms:get_custom_field 'company_tel' masterpage='globals.php' />

Simply copy-n-paste the entire statement to use its output as a parameter for the cms:if tag, e.g. like this:
<cms:if "<cms:get_custom_field 'company_tel' masterpage='globals.php' />" >
<cms:get_custom_field 'company_tel' masterpage='globals.php' />
</cms:if>

Just make sure to use double-quotes for the parameter else Couch will take it as a literal string.
There is no limit to this nesting. For example, the cms:get_custom_field itself could have another tag as its input.

If the nesting appears confusing to see, let us simplify it a bit by first holding the first tag's output in a local variable. The following will work exactly as the previous statements.
Code: Select all
<cms:set company_tel="<cms:get_custom_field 'company_tel' masterpage='globals.php' />" />   
<cms:if company_tel >
    <cms:show company_tel />
</cms:if>

You might also want to take a look at not_empty tag that can also be used for this very purpose (http://www.couchcms.com/docs/tags-refer ... empty.html).

Hope this helps.
That works a treat, and that nested conditional is a very, very useful feature - thanks for explaining it, I have a few more instances I can now use it!

I have two more templates of this site (easy ones, contact and homepage) I am currently working on to setup and thats it finished (approx. 11 hours start to finish which is pretty impressive considering I've had to read a fair bit of the docs and modified the way I initially set things up to make life easier).

Thanks again!
3 posts Page 1 of 1
cron