Problems, need help? Have a tip or advice? Post it here.
8 posts Page 1 of 1
Hi, KK
Something's not right here:
Code: Select all
        
<cms:capture into='count' >
      <cms:pages masterpage='blog.php' custom_field="has_tag=<cms:show k_page_name />" count_only='1' />
</cms:capture>
<cms:if count gt '0' >'<cms:show count />'</cms:if>

This construction works as expected:
Code: Select all
<cms:set count="<cms:pages masterpage='blog.php' custom_field="has_tag=<cms:show k_page_name />" count_only='1' />" />
<cms:if count gt '0' > '<cms:show count />' </cms:if>

I thought you might take a look at this.
I tested and the capture version seems to be working just fine for me. What exactly is the problem that you are encountering? Please let me know.
I have found a very unusual set of messing with variables.
Take a look:
Code: Select all
  <cms:pages masterpage='tags.php' >
  <cms:capture into='count' >
      <cms:pages masterpage='blog.php' custom_field="has_tag=<cms:show k_page_name />" count_only='1' />
  </cms:capture>
  <cms:show count />:&emsp;
  <cms:if count gt '0' ><cms:show k_page_title /> - '<cms:show count />'</cms:if>
  </cms:pages> 

Output:
1:  2:  0:  2:  1:  1:  1:  1:  1:  2:  1:  1:  0:  0:  3: etc


Edit: name of the counter 'count' can be set to 'cow' but result is the same. So, it's not the scope issue.
Could you also show what the expected output is?
What do you get when you use the following method instead?
Code: Select all
<cms:set count="<cms:pages masterpage='blog.php' custom_field="has_tag=<cms:show k_page_name />" count_only='1' />" />
KK wrote: Could you also show what the expected output is?
What do you get when you use the following method instead?
Code: Select all
<cms:set count="<cms:pages masterpage='blog.php' custom_field="has_tag=<cms:show k_page_name />" count_only='1' />" />

Sure. With use of 'set' the conditional if count gt '0' is executed properly.
for the constructed output
Code: Select all
<cms:show count />:&emsp;
  <cms:if count gt '0' ><cms:show k_page_title /> - '<cms:show count />'</cms:if>
It goes like this, showing tag names alongside the count of pages associated with tag.
1:  map - '1' 2:  vertical - '2' 0:  2:  one-page - '2' 1:  2015 - '1' 1:  bootstrap - '1' 1:
This is not critical at all right now.

I can set up demo ftp for you to investigate later. There got to be some difference in the way both variables are set.

I checked code and with SET you send array and with CAPTURE it is just $html. Html means text and maybe there can't be a conditional (if text gt '0'), maybe text should be converted to numeral first? This is just a thought. I'm sorry this looks stupid maybe, i'm not yet familiar with php.

I really just like what i found :) kinda easter egg :lol: .
Regards
I think I was able to recreate the problem you are running into.

To understand that, a bit of a theory first -
As, I'm sure, you know PHP (like all proper languages) has a concept of data-types e.g. integer, float, string, boolean, arrays etc.

Couch, being much simpler, works with only one datatype - that is string.
So, for example, while comparing '0' to '1', we are actually working with strings and not numbers.

That is normally not a problem as PHP recognizes that the the two strings being compared above are numerals and internally does type-juggling to convert the strings to numbers and then does the comparison.

With that bit of theory understood, I can come to the actual problem.
The cms:capture tag captures everything between its two tags, including white-spaces, newlines etc.

I found that if there was whitespace (newline was not a problem) *after* the number being captured, for some reason PHP did not consider the value to be a number. To illustrate it, the following does not work
Code: Select all
' 1   ' > '0'

while the following does -
Code: Select all
'   1' > '0'

So to avoid the trailing whitespaces, if you were to change your <cms:capture> block to either make it flush left to the document or make it as follows (notice how there is no space between the ending capture tag and the value being captured), things work as expected -
Code: Select all
<cms:capture into='count' >
      <cms:pages masterpage='blog.php' custom_field="has_tag=<cms:show k_page_name />" count_only='1' /></cms:capture>

I think, for numeric data, the best way would be to leave no spaces on either side i.e. make it as follows
Code: Select all
<cms:capture into='count' ><cms:pages masterpage='blog.php' custom_field="has_tag=<cms:show k_page_name />" count_only='1' /></cms:capture>

Please make the suggested change and see if it works for you now.
Yup. No spaces/returns approach works!

PS Does cms:show trims spaces somehow? Spaces are not present in generated html when cms:capture is used with spaces. I.E. "<cms:show count />" would give "1".
8 posts Page 1 of 1