Unyson icon indicating copy to clipboard operation
Unyson copied to clipboard

Do we have javascript html parser that we could use in title_template?

Open danyj opened this issue 11 years ago • 35 comments

I am using this for builder element title

'title_template' => '{{-title}}{{ if (o.title) { }} : {{-o.title}}{{ } }}',

which result in screenshot_6

I can clean it up with this

o.title.replace(/(<([^>]+)>)/ig,"")

screenshot_3

but I rather display it as html.

Is it possible ?

danyj avatar Jul 24 '15 18:07 danyj

  • {{ console.log("Hello"); }} - Execute any javascript code
  • {{- some.variable }} - Print a variable html escaped
  • {{= some.variable }} - Print a variable (no html escape)

ghost avatar Jul 24 '15 18:07 ghost

Bless you !

screenshot_4

danyj avatar Jul 24 '15 20:07 danyj

Darn thing , was hoping to soon , see this , cant nail drag and drop inside column if html is present

http://screencast.com/t/ffnNXQaVYf

seems like it looks for specific height

danyj avatar Jul 24 '15 20:07 danyj

https://github.com/ThemeFuse/Unyson-PageBuilder-Extension/issues/25#issuecomment-124544398

ghost avatar Jul 24 '15 21:07 ghost

+1000

danyj avatar Jul 24 '15 21:07 danyj

@moldcraft sorry for all new things , just picking up where I left off.

danyj avatar Jul 24 '15 21:07 danyj

no problem.

P.S. Next issue that I will do is this then this. Other issues may be inactive until I will finish those 2. If you have a free developer in your team, he can pick any issue and try to debug and resolve it, we accept pull requests :)

ghost avatar Jul 24 '15 21:07 ghost

thnx bud , will forward to team and help around. I know how messy all those issues can get. Thnx for all the help.

danyj avatar Jul 24 '15 21:07 danyj

sorry but I need small help on this title thing ,

this , gets me the select option value for revolution slider

{= o.revslider}

http://prntscr.com/7xcx6l

but I am after the title not the value

http://prntscr.com/7xcxib

the o = object does not return anything else , this is console log for it

Object {revslider: "kenburns_fullwidth"}

I tried also with fw.opg but no luck, is there any way to do this ?

danyj avatar Jul 26 '15 23:07 danyj

At the moment, no.

ghost avatar Jul 27 '15 07:07 ghost

@danyj did you try with Text block and Image shortcode? The code below seem didn't work with that shortcodes

'title_template' => '{{-title}}{{ if (o.title) { }} : {{-o.title}}{{ } }}',

dylan-ngo11 avatar Jul 27 '15 09:07 dylan-ngo11

Until the possibility will be added, you can localize script an array with all choices from revslider option array('choice_id' => 'Choice Title')

{{= _localized_revslider_choices[ o.revslider ] }}

ghost avatar Jul 27 '15 10:07 ghost

@duongancol , yes above, https://github.com/ThemeFuse/Unyson/issues/759#issuecomment-124717955

those work fine no issues , what I am talking about now is the select option not textarea or text ,

example

    'choice-1' => __('Choice 1', 'fw'),
    'choice-2' => array(
        'text' => __('Choice 2', 'fw'),
        'attr' => array('data-foo' => 'bar'),
    ),

this will than return choice-1 instead the title Choice 1

@moldcraft I see what you mean. Will try that until the feature is added.

danyj avatar Jul 27 '15 11:07 danyj

@duongancol the confusion u might have is the o.title , I used that as option name

use this for text-block

'title_template' => '{{-title}}{{ if (o.text) { }} : {{-o.text}}{{ } }}',

and this for image

'title_template' => '{{-title}}{{ if (o.image) { }} : {{-o.image}}{{ } }}',

u might want to tweak image and add img tag around it if u want it displayed

danyj avatar Jul 27 '15 11:07 danyj

in short ,

o.some_option_name 

is this for example

http://prntscr.com/7xirrx

danyj avatar Jul 27 '15 11:07 danyj

@danyj when I add

'title_template' => '{{-title}}{{ if (o.image) { }} : {{-o.image}}{{ } }}',

to Image shortcode It showed like that : http://prntscr.com/7y8mgh

dylan-ngo11 avatar Jul 29 '15 02:07 dylan-ngo11

@duongancol this is console log for o.image http://prntscr.com/7zx7ci

so you would need

o.image.url

or

'title_template' => '{{-title}}{{ if (o.image) { }} :  <img  style=\'width:100px;height:auto;\' src=\'{{-o.image.url }}\' /> {{ } }}',

http://prntscr.com/7zxaeb

danyj avatar Aug 02 '15 12:08 danyj

Thank @danyj

dylan-ngo11 avatar Aug 07 '15 04:08 dylan-ngo11

@moldcraft those notations are very space sensitive , you said

{{ console.log("Hello"); }} - Execute any javascript code

but that is not true , we must do those

{{ } , }}}

all the time , and if we space the code we get template error

example I expect this to work

'template' => '{{
    var bgtype = background.bg_type;
    var hasimg = background.image;

    if (hasimg && bgtype == \'image\') { 

        \'<img style="width:80px;height:auto;" src=\'hasimg\'/>\';

    }  else { 

        title

    }   
}}'

but it does not , than I do this

'template' => '{{
    var bgtype = background.bg_type;
    var hasimg = background.image;

    if (hasimg && bgtype == \'image\') { }}

        \'<img style="width:80px;height:auto;" src=\'{{-hasimg}}\'/>\';

    {{ }  else { }}

        {{=title}}

  {{ }  

{{ } }}'

again error ,

until I do

'template' => '{{var bgtype = background.bg_type;var hasimg = background.image;if (hasimg && bgtype == \'image\') { }}

        \'<img style="width:80px;height:auto;" src=\'{{-hasimg}}\'/>\';

    {{ }  else { }}

        {{=title}}

  {{ }  

{{ } }}'

danyj avatar Oct 09 '15 12:10 danyj

I think it's related to new lines, not to spaces.

Something similar https://github.com/jashkenas/underscore/issues/35

Better do

'template' => '{{ '
    .'var bgtype = background.bg_type; '
    .'var hasimg = background.image; '
    ...

ghost avatar Oct 09 '15 12:10 ghost