Of course I got it sorted 5 minutes after posting last night.
Walter, thank you for the suggestion. The code I posted was by the author’s admission a guess, and not ideal. Straight PHP can and does work just fine except yours didn’t quite do so, though I’m sure it would.
In any case, I’m using a very handy “if” snippet written in what appears(?) to be straight PHP If - If | MODX Documentation, that allows me to write conditionals using a more familiar (albeit regional) syntax.
Here’s the result:
[[!If?
&subject=`[[!+twitter]]`
&operator=`empty`
&then=``
&else=`<a href="[[!+twitter]]" title="[[!+twitter]]">Twitter</a>`
]]
Alternatively, this one does the same as above but also passes the value (if any) to a filter that returns a list of resources (a tag filter):
[[!If?
&subject=`[[!+specialties]]`
&operator=`empty`
&then=``
&else=`Specialties:
<span>
[[!toLinks?
&items=`[[+specialties]]`
&target=`22`
&tpl=`tagResult`
&tagKey=`tag`
]]</span>`
]]
@Ernie - I believe the “isempty" part is essentially the “if” you’re looking for.
Todd
https://xiiro.com
On Mar 11, 2015, at 8:41 AM, waltd email@hidden wrote:
Are you allowed to use straight PHP in these snippets, or must you encapsulate your code in these pidgin :isempty
type statements?
Perhaps the simplest way to do this is to create a function that you can call yourself, so you can use more straightforward code there, and not in your view, which should be “dumb”. Think of this like a Rails helper method.
<?php
function twitter_link($twitter){
if(empty($twitter)) return '';
return 'Twitter';
}
?>
[[+twitter_link([[+twitter]])]]
Does that make sense?
Walter
dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options
dynamo mailing list
email@hidden
Update your subscriptions at:
http://freewaytalk.net/person/options