You are here

Conditional description

3 posts / 0 new
Last post
martos
Offline
Donator
Joined: 11 years
Last seen: 1 week
Conditional description

First sorry if it is not the correct place for the post...
So I want to make simple check if index_title is longer than 50 characters and if it is to move the content of index_title from the first occurance of "-" to the end to index_description. For example:
index_title is: bla bla bla 123 - blablablabla bla blablablabla blablablabla blabla blablabla blablablabla blablablabla blabla blablabla blablablabla blablablabla
I want the result to be:
index_title: bla bla bla 123
index_description: blablablabla bla blablablabla blablablabla blabla blablabla blablablabla blablablabla blabla blablabla blablablabla blablablabla
Thank you!

WGMaker
Offline
WGMaker's picture
WG++ Team memberDonator
Joined: 12 years
Last seen: 2 hours
Is the support helpful?
support us

Hi Martos,
 
I give you three possible solutions.
 
For all three you will need to prepare the condition of the > 50 characters in title and further save the unchanged title in a temp element:
 
index_temp_1.modify {clear} * make sure is empty
index_temp_1.modify {addstart|'index_title'} *copy title
index_temp_6.modify {calculate(type=char format=F0)|'index_temp_1' #} *number of chars
 
The first solution , with regex , is the most compact but needs some understanding of regular expressions:
 
index_title.modify {substring(debug 'index_temp_6' > "50" type=regex)|'index_temp_1' "(\A.*)-"} *change title under condition > 50 chars
index_description.modify {substring(debug 'index_temp_6' > "50" type=regex)|'index_temp_1' "-(.*$)"} *move part of title to desc under condition
 
*The second solution works with element split by means of the standard element split character |
 
index_temp_1.modify {replace(debug 'index_temp_6' > "50")|-|\|} * split copied title in parts at -
index_temp_2.modify {substring(debug type=element)|'index_temp_1' 0 1} *first part
index_title.modify {replace(debug 'index_temp_6' > "50")|'index_title'|'index_temp_2'} *replace title by its first part
index_temp_2.modify {substring(debug type=element)|'index_temp_1' 1 1} *second part}
index_description.modify {addend('index_temp_6' > "50")|'index_temp_2'}
 
The third works with indices (places)

index_temp_2.modify {calculate(type=char format=F0)|'index_temp_1' "-" @} * index_of (place) of the - character
index_title.modify {substring(debug 'index_temp_6' > "50" type=char)|0 'index_temp_2'} * the first part 0=start 'index_temp_2' = length
index_temp_2.modify {calculate(format=F0)|1 +} * add 1 to get past the - char
index_temp_3.modify {substring(debug 'index_temp_6' > "50" type=char)|'index_temp_1' 'index_temp_2'} * the second part upto the end 'index_temp_1' = source element, 'index_temp_2'= start , length not required = default to end
index_description.modify {addend('index_temp_6' > "50")|'index_temp_3'}
 
succes        Jan

martos
Offline
Donator
Joined: 11 years
Last seen: 1 week

Hi WGMaker,
Thank you very much for your answer! It is written to be understood perfectly even by people who are not familiar with the syntax.
Keep up the good work! :)

Log in or register to post comments

Brought to you by Jan van Straaten

Program Development - Jan van Straaten ------- Web design - Francis De Paemeleere
Supported by: servercare.nl