← Back to team overview

zim-wiki team mailing list archive

Re: Is there any way to cancatenate strings in template?

 

Earlier I missclicked and replied only to Jaap Karssenberg's address,
so our further dialog doesn't appear here. I'am sending this message to
share solution of my problem. May be it'll be useful for somebody.

Thank you Jaap for help, both ways work great.

2017-03-23 20:43 GMT+02:00 Jaap Karssenberg <jaap.karssenberg@xxxxxxxxx>:

> I found two options
>
> Option 1: avoid the newlines
>
> [% FOR tag IN tags %]@[% tag %] [% END %]
>
> Option 2: might be undocumented, but this should work as well
>
> [% FOR tag IN tags -%]
> @[% tag %]
> [%- END %]
>
> In this case the "-" should result in removal of the newlines.
>
>
> Hope this helps,
>
> Jaap
>
>
> On Thu, Mar 23, 2017 at 5:24 PM Eugene Just <gekazoid@xxxxxxxxx> wrote:
>
>> I made automatic adding tags to the top of new page based on "parents" of
>> new page.
>> For example I have next hierarchy of pages:
>> /Goods/Cars/German
>> and i made new sub-page in German. New page should have next tags:
>> @goods @cars @german
>>
>> I've already made it with this template
>> ======= [% page.basename %] =======
>> [% '' %]
>> [% tree = page.section.lower() %]
>> [% tags = tree.split(':') %]
>> [% FOR tag IN tags %]
>> @[% tag %]
>> [% END %]
>>
>> But in this variant each tag printed on new line, it's unpretty. With
>> string concatenating I wanted to join it and print it in one line.
>> Or maybe there is a way don't print each string with new line?
>> Thank's
>>
>> 2017-03-23 18:03 GMT+02:00 Jaap Karssenberg <jaap.karssenberg@xxxxxxxxx>:
>>
>> Afraid there is no "join" method at this moment. Can you show the example
>> what you try to do? Maybe we can come up with a work around to achieve the
>> same result?
>>
>> -- Jaap
>>
>>
>> On Thu, Mar 23, 2017 at 4:56 PM Eugene Just <gekazoid@xxxxxxxxx> wrote:
>>
>> Hello guys.
>> I'am trying to edit "Default" wiki page template to fit it to my purposes.
>> I've read all about templates in the manual but didn't find how to
>> concatenate strings, is it possible?
>> I've tried standart python ways, like:
>> string3 = string1 + string2
>> and
>> ' '.join(wordslist)
>> Nothing works.
>>
>> split method works and join doesn't work.
>> _______________________________________________
>> Mailing list: https://launchpad.net/~zim-wiki
>> Post to     : zim-wiki@xxxxxxxxxxxxxxxxxxx
>> Unsubscribe : https://launchpad.net/~zim-wiki
>> More help   : https://help.launchpad.net/ListHelp
>>
>>
>>

References