juek / CustomSections

Developer plugin for rapid prototyping of custom section types in Typesetter CMS
GNU General Public License v2.0
3 stars 7 forks source link

Js on loaded content when inline edit.+ one level arrays echo(simple) #9

Closed a2exfr closed 7 years ago

a2exfr commented 7 years ago

one level array elements echo syntax {{array|key}}

juek commented 7 years ago

How do subkeys work? Can you give me an example? I just don't get it :)

a2exfr commented 7 years ago

For example in section values we have array 'button_link' => array("url"=>'some link', "prefix"=> "some prefix", "title"=>"12345");

now in section[content] we echo it in this way: <a href="{{button_link|url}}">{{button_link|title}}</a>

this is first simple approach for one level arrays

subkey is just a word)

juek commented 7 years ago

Ok, got it. Works like a charme, see commit

Great!

juek commented 7 years ago

I don't believe we need more than 1-dimensional arrays. Very cool!
Now we only need a conditional rendering. Maybe sth. like

{{if[[show_elements}}<div>ELEMENT 1</div>{{show_elements]]if}} 
{{else[[show_elements}}<div>ELEMENT 2</div>{{show_elements]]else}} 

Is there a common standard for such stuff? I haven't used templating any languages lately O_o

juek commented 7 years ago

Espression Engine uses

{if age == 30}
  You are 30!
{if:elseif username == 'Bob'}
  You are Bob!
{if:else}
  You're not 30 or Bob. That's all we know.
{/if}
juek commented 7 years ago

Smarty goes a similar route with

{if $name eq 'Fred'}
    Welcome Sir.
{elseif $name eq 'Wilma'}
    Welcome Ma'am.
{else}
    Welcome, whatever you are.
{/if}

We certainly will not implement a complete template engine here, but we also shouldn't alienate TE users by doing common things in an unusual manner. Maybe...

{if{show_elements}}<div>ELEMENT 1</div>{{show_elements}if} 
{else{show_elements}}<div>ELEMENT 2</div>{{show_elements}else} 
a2exfr commented 7 years ago

Template engine is too much... of cause this things {{val}}is really unflexible. If think we should leave conditions as is and not invent a bicycle. And if really necessary use $section[values] Because, we need not only conditions, but foreach loop for upcoming multi image field(is actually ready,I try to push it in evening) Of cause, we can do simple foreach syntax like {{value|%}} . Ok, now we need to echo each image in div or li. Let's do for example {{value|%|<li>|</li>}}not pretty but can be. And what to do, if suddenly we need add class to first of li ?)

juek commented 7 years ago

Agreed. Although a basic boolen condition based on a value that is (or evaluates to) true|false, we could support {{if:value}}{{/if}} with a simple regex, any other conditional rendering based on multiple distinct values becomes complicated. And adding support for loops is definitively overkill. For building such sections types, some PHP knowledge is inevitable. Let's keep it with simple values and arrays.