Closed pieterhertogs closed 4 years ago
Hi @pieterhertogs
This is because we trim all templates.
You could try adding
instead of a single space.
Let me know!
Hi @JoryHogeveen
With
this is result in css: https://d.pr/i/YnNeSM
Ah, the output is for CSS, didn't know that. Since this is an edge case then I'll have to think about how to solve this.
The terms are CSS classes in HTML
Maybe good to know: this worked fine for year untill update 2.7.17 (since that update white space in each loop disappears)
Yeah, It seems this might have been a bug that is fixed here: https://github.com/pods-framework/pods/pull/5641
While I understand this is inconvenient for you, it actually was a bug that this was possible since all output should be sanitized (and therefore trimmed).
I have been looking at the code and the magic tags do support a before/after tag as well.
Format:
{@name,callback,before,after}
Callback: a function/method to run the value through. Before/After: Content to put before or after the value.
So in your case this should work:
{@field,,, }
. I know, it looks terrible but the 3 comma's will make sure the space is passed as the correct parameter.
Thank you, that makes sense why it stopped working :-) I added the comma's and space, but without luck. Maybe I can add a function that adds a white space charactere before and after the value. But how does that work? Where do I put the function?
Hi @pieterhertogs
I've did some tests and all output is sanitized, even with a plugin.
This means that you cannot use the [each]
loop for this. You'll need to pass everyting into a function that outputs the classes.
Example:
function term_slug_css_classes( $values ) {
$values = wp_list_pluck( $v, 'slug' );
return implode( ' ', $values );
}
You can use this function like so: {@custom_taxonomy,term_slug_css_classes}
(without the wrapping [each]
.
You can add functions in a custom plugin or in your theme. When using your theme always make sure it's a child theme (unless you have a custom theme). Closing this here!
Cheers, Jory
@JoryHogeveen @sc0ttkclark Trying to get the logic on why we would trim spaces out of an each loop, considering everything being output within the each loop is a template to be replicated exactly, spaces included.
To me this is a breaking bug.
This is 100% a breaking bug, and using each for CSS is far from an edge case. The Each output shouldn't be sanitised for white-space. Perhaps it would benefit from a whitespace="false" setting, but changing the default on this to be true is a change not a bug.
We wrote a walk through on how to use this in exactly this way, and it received a surprising amount of traffic. The change just broke a client site after they did a minor version update.
Templates keeps pods within reach for a lot of people that couldn't otherwise go out and write custom plugins. Don't break that!
Rolled back to a previous version for now, in the hope you guys fix this.
Issue Overview
Each loop white space character is deleted in Pods template
Expected Behavior
Each loop with white space character in Pods template should be outputted: [each custom_taxonomy]{@slug} [/each] -> term1 term2 term3
Current Behavior
Each loop white space character is deleted in Pods template, for example: [each custom_taxonomy]{@slug} [/each] outputs term1term2term3 instead of term1 term2 term3
Steps to Reproduce (for bugs)
WordPress Environment
Pods Package Export (helpful!)