pods-frontier
pods-frontier copied to clipboard
new template tag [between] needed in frontier
Hi I'm using frontier template tags extensively. I found a case where I need a new tag: [between]
The Use Case: I'm coding a chart in a template. I use [before] and [after] tags to define the javascript needed for the chart. The chart data is build with array notation (i.e: ["RM01", {@data1},{@data2}, 25])
The problem is that each array for each element needs to end with a "," character. All but the last that has nothing.
We only has "[once]" tag and nothing more. I think we need [between] so we can output things between an item and the following (so nothing is outputted before the first item and nothing after the last item).
I would want to help developing this feature, if someone could point me where I should have to look into the code so I could make it work and propose a pull request.
Thanks
This does sound useful. I wouldn't know where to tell you to look as I'm not very familiar with the source code for Frontier. David Cramer ( @Desertsnowman ) wrote it. I would recommend searching the source for what powers the before and after blocks. What you are talking about doing is very similar.
@Desertsnowman Didn't you tell me something last time we spoke about a counter that's running for each iteration?
I have been toying with an idea to store values to use later.
something like [store name="my_var"] stuff , {@tag} etc.. [/store]
I can then use it later like [print name="my_var"]
.
I could look at making an array type on this.
[store name="my_array" type="array"] stuff , {@tag} etc.. [/store]
Then I can print out the array in a join. [print join="," name="my_array"]
Having arrays would actually be nice since I could then use the [each] on it like:
[each my_array] my value is {{this}} with index {{index}} [/each]
sound like a good solution?
@Desertsnowman That sounds cool, but I don't see how that solves @carlosrovira problem.
He wants if he has a template that loops through 3 items, to set content to only run between item 1 and 2, and between 2 and 3, but not before 1 or after 3.
Bot solutions are useful:
a) Mine, is a solution that will make more useful for people with less programming skills since it's typical to control a loop with a counter and make if-else to output things elements output. Typical is my case with javascript array that need "," between elements.
b) David store tag could be useful as well in my case since each step in the loop can't store vars. If I use a $counter var, each step is reset to 0. With store and $pods->getTotalRows() I can do something similar.
@Desertsnowman is the store tag available now?
Thanks
@Desertsnowman have you plans to integrate your store/print in the current state? Maybe I could do [store name="counter"]++$counter[/store] and then opening php in the template store in a php var to use? $counter = [print name="counter"] so I can make if-else? Sounds feasible? Thanks