Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to add specific id to builder sections ? #275

Closed
danyj opened this issue Feb 23, 2015 · 73 comments
Closed

How to add specific id to builder sections ? #275

danyj opened this issue Feb 23, 2015 · 73 comments

Comments

@danyj
Copy link
Contributor

danyj commented Feb 23, 2015

I am trying to assign specific id attribute to sections. I tried to use required option for the id but it seems like is not effective on modals #274 .

Now if I print the builder json I do see that each section in the builder has it's own object.
But the $attr array is returning only the section options.
Is there any way for me to get that object index or anything very specific to each section so that I can generate id's from it inside

framework-customizations\extensions\shortcodes\shortcodes\section\views\view.php
@danyj
Copy link
Contributor Author

danyj commented Feb 23, 2015

I do see that you are adding the section ID in the builder
http://screencast.com/t/yRSzFKx5e11
but how to add it in frontend?

@ghost ghost assigned sergiubagrin Feb 23, 2015
@ghost ghost added the question label Feb 23, 2015
@danyj
Copy link
Contributor Author

danyj commented Feb 25, 2015

Any way we can get this to work ?

@danyj
Copy link
Contributor Author

danyj commented Feb 27, 2015

No suggestion on this one?

@sergiubagrin
Copy link
Contributor

Hi @danyj

We will check it on monday. @moldcraft is missing 3-4 days and i need to discuss with him.

@ghost
Copy link

ghost commented Mar 3, 2015

I do see that you are adding the section ID in the builder
http://screencast.com/t/yRSzFKx5e11

That is temporary unique backbone Model.cid. It is lost/auto-generated on page refresh, it is used to find/identify builder item object (for e.g. on sortable drag from one column to another) and it is used only in backend internally.

I am trying to assign specific id attribute to sections.

Sorry for asking that late: Why do you need that?

@danyj
Copy link
Contributor Author

danyj commented Mar 3, 2015

I am adding all section custom css to head. Background, box model or any section css options. Thus I need the id for each section.

@ghost ghost added enhancement and removed question labels Mar 3, 2015
@ghost ghost assigned ghost and unassigned sergiubagrin Mar 3, 2015
@danyj
Copy link
Contributor Author

danyj commented Mar 3, 2015

To make it more clear. I am against anything like this http://prntscr.com/6cc57f
All of that belongs in head or inside dynamic CSS.
So in order to keep html clean I used my own class
https://github.com/YJSGframework/yjsg/blob/master/includes/yjsgcore/classes/yjsg.dochead.class.php#L174 ( feel free to use that approach )
and this way I can do this in section/column/row view or any theme file
http://prntscr.com/6cc6jg

and in inc/static.php
I do this
http://prntscr.com/6cc81n
so this way all that inline goes inside of the head embedded
http://prntscr.com/6cc8qj

and html is clean.

Now the auto generated ID for section/column, helps me add css in head for that specific column/section only.

@ghost
Copy link

ghost commented Mar 3, 2015

I understood what you want to do.
I will try to figure out a (simple) solution in 1-3 days.

@ghost
Copy link

ghost commented Mar 8, 2015

@moldcraft I will try to figure out a (simple) solution in 1-3 days.

Sorry, I haven't done it.

I will do it soon (no more exact promises).

@danyj
Copy link
Contributor Author

danyj commented Mar 8, 2015

Not a problem. I am busy finalizing all theme options and in week or so will move to page options so it is ok for now.

@ghost
Copy link

ghost commented Mar 11, 2015

How/Where do you generate the css?

@danyj
Copy link
Contributor Author

danyj commented Mar 11, 2015

inside the view I am getting all section/row extra options and using my dochead class to send them to head
http://prntscr.com/6fgmnl

@danyj
Copy link
Contributor Author

danyj commented Mar 11, 2015

this is basically all I need

$atts['sectionid']  //or 
 $atts['rowid']

@ghost
Copy link

ghost commented Mar 11, 2015

How you send them to head inside view? The view is rendered after head when the post content is generated.

@danyj
Copy link
Contributor Author

danyj commented Mar 11, 2015

:) you did not believe me before , I mentioned it many times, I used my class to do this.
https://github.com/YJSGframework/yjsg/blob/master/includes/yjsgcore/classes/yjsg.dochead.class.php

What my class does is just adding your css to the ['cssinhead'] array,
https://github.com/YJSGframework/yjsg/blob/master/includes/yjsgcore/classes/yjsg.dochead.class.php#L174

and I implode that array in static.php

all css is in its place. it was bit of a hassle but is well worth it and html is clean
I take this

http://prntscr.com/6fgrif

vs this
http://prntscr.com/6cc57f

any time.

@danyj
Copy link
Contributor Author

danyj commented Mar 11, 2015

oh , and the static.php I use to print everything is not section/static.php

it is theme_name/inc/static.php

@ghost
Copy link

ghost commented Mar 12, 2015

I found the solution very simple:

<?php
$auto_id = 'auto-id-'. fw_unique_increment();
ThzDochead::getDocument()->addCssInHead('#'. $auto_id .' { ... }');
?>
<section id="<?php echo $auto_id ?>" ...

or I am missing something?

@ghost ghost removed the enhancement label Mar 12, 2015
@danyj
Copy link
Contributor Author

danyj commented Mar 12, 2015

I was thinking about the same thing and had my own function ( nice to see you have one ) to do that but it does not sit well with me because user might want to add additional css specific to the id and he will never have it right. I know I can add the class for them to style it but if I have 5 sections in the builder this was desired output

thz_section_id0
thz_section_id1
thz_section_id2
thz_section_id3
thz_section_id4

since that is how they are saved in DB for that page
it is an array with keys 0 - 4

is it hard to add the id inside the $attr array ?

@ghost
Copy link

ghost commented Mar 12, 2015

is it hard to add the id inside the $attr array ?

Shortcodes doesn't have ids, they are stored as non assoc array.


Another solution would be:

  1. Copy the hidden option-type to your theme.

  2. Rename the type to something like thz-id.

  3. Change the _get_value_from_input method to

    protected function _get_value_from_input($option, $input_value)
    {
        if (empty($input_value)) {
            return fw_rand_md5();
        } else {
            return (string)$input_value;
        }
    }
  4. Add the option in extensions/shortcodes/shortcodes/section/options.php

    'id' => array( 'type' => 'thz-id' ),

If input value will be empty, it will be generated, if it was already generated. it will stay the same.

@danyj
Copy link
Contributor Author

danyj commented Mar 12, 2015

ok will try that and by looks of it it might just do what I need. thank you!

@danyj
Copy link
Contributor Author

danyj commented Apr 17, 2015

about the new issue if builder disabled , i seen it before , thought that is how you wanted since you did not make the short codes available outside the editor

@danyj
Copy link
Contributor Author

danyj commented Apr 17, 2015

note that I am using the multi picker you last changed
#442 (comment)

@ghost
Copy link

ghost commented Apr 17, 2015

multi pickers still dont work properly

some details? what actually doesn't work?

@danyj
Copy link
Contributor Author

danyj commented Apr 17, 2015

is not taking selected value ,
here video
http://screencast.com/t/b60Hzu26gZ8

@danyj
Copy link
Contributor Author

danyj commented Apr 17, 2015

@ghost
Copy link

ghost commented Apr 17, 2015

Thanks for the investigation. I am already fixing it now. The problem is that it doesn't take in consideration $option['value'] at all, it works only with $input_value, and event doesn't check if $input_value is null (like other options do), it uses it right away.

ghost pushed a commit that referenced this issue Apr 17, 2015
@ghost
Copy link

ghost commented Apr 17, 2015

Fixed multi-picker and other option types.

#275 (comment)
Now we found another problem, because of this (which makes the unique-id option-type _get_value_from_input() method to be executed on every post save) all upload options "lost" their values on post save, because of this.

If I will not find some workaround, I will change the upload and multi-upload options to not ignore $option['value'] (default value set manually, in this case it is set "manually").

I wrote that without verifying/testing. The problem was actually here.

@ghost
Copy link

ghost commented Apr 17, 2015

Anything else needed to be fixed in this issue? (except this)

@danyj
Copy link
Contributor Author

danyj commented Apr 18, 2015

i took an out bud , 2:30 here, will test first thing in the morning and report back

@danyj
Copy link
Contributor Author

danyj commented Apr 18, 2015

This one is for you
http://prntscr.com/6v66l6

scratch the previous bug report on special heading , seems to work fine

@ghost
Copy link

ghost commented Apr 18, 2015

Thank you too, for investigations and feedback.

@ghost
Copy link

ghost commented May 26, 2015

This (Ctrl+R) will be possible in the next version of Unyson (and page-builder extension).

@danyj
Copy link
Contributor Author

danyj commented May 26, 2015

Nice work. Question , will it work in theme admin when ajax save is on ?

@ghost
Copy link

ghost commented May 26, 2015

I don't see any connection with Theme Settings.
Give more details pls

@danyj
Copy link
Contributor Author

danyj commented May 26, 2015

I use builder inside theme options , also have section and columns
but save is ajax based not like posts
so I am not sure if I use unique id in there and save via ajax if it will be able to check the uniqueness

@ghost
Copy link

ghost commented May 26, 2015

It should work.

@danyj
Copy link
Contributor Author

danyj commented May 26, 2015

ok , np , if i have trouble will let you know. thnx for the great work and support.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants