if (empty($newsdate))if it ($newsdate) is empty it should NOT return, but true! Maybe that is what you meant - but it is not what you said
Is not returning empty, even if it is ’empty’.
Maybe that is what you meant - but it is not what you said
I would like to also point out that by using a CMS you are depending on others to support your use of it (unless you write your own person CMS)
Using a well tried extra is only a small step further.
Well the odd question/PHP issue is hardly "depending"when I said depending I was referring to a previous post of yours
I’m slightly wary of installing a separate package because it creates a reliance on someone supporting it etc.reliance - depending - kinda similar I think, I was not being critical of your stance, just pointing out that when we use a cms we are relying on others code and if use a separate package it is just a little bit more code of others.
But when you have a question, or something is niggling you, that’s what support forums are for surely?Asking questions IS what the forum is all about so I am definitely not trying to be critical about that. So you just misunderstood me when you said
Well the odd question/PHP issue is hardly "depending". I have 5 MODX sites and for the most part get on fine. But when you have a question, or something is niggling you, that’s what support forums are for surely?
I know a bit of PHP, I can piece together some simple if/else stuff etc. But ultimately, I don’t know much!
I’m wanting to loop through a number of template variables, churning out their output for each number.
So for example I have TVs named News 1 to News 15 - and I want to ouput each of them in turn as long as it’s not empty (as there’s not always 15 news item).
So I wanted to basically do this:
$newsitem = "[[*News $i]]";
The looping is working if I manually put in a number say [[*News 1]] - but I can’t seem to use $i in this context.
Is there a way that it can be achieved?
Thanks
<?php
// call example:
// [[loopTVs? &tvname=`imgsrc` &tpl=`mychunk`]]
// chunk example:
// <img src="[[+imgsrc_[[+suffix]]]]" title="[[+imgtitle_[[+suffix]]]]" />
// <img src="[[+value]]" title="[[+imgtitle_[[+suffix]]]]" />
if ($tvs = $modx->getCollection('modTemplateVar', array('name:LIKE' =>$tvname.'_%'))){
foreach ($tvs as $tv){
$value = $tv->getValue($modx->resource->get('id'));
if (!empty($value)){
$ph['name'] = $tv->get('name');
$nameparts = explode('_',$ph['name']);
$ph['suffix'] = $nameparts[1];
$ph['value'] = $value;
$output .= $modx->getChunk($tpl,$ph);
}
}
}
return $output;
I still am pondering why two people both have 17 at the end of their nicknames - not really important though and do not expect or need an answer!