• Resolved Blackbam

    (@blackbam)


    Just tried the plugin and it is essentially great. However if I make a block – e.g. with background color – and insert multiple of those blocks into a page, when changing the background color for one block it is changed for all blocks within that page. This does not make sense?

    If I want to insert a block element with a green, a yellow and a red background within the same page it should be possible. Across different posts and pages the problem is not existing.

    What am I missing here? Thanks a lot!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Nikita

    (@nko)

    Hi,

    Can you provide me a code example where you set the block background? You must make it using a unique classname/ID, or add styles inline.

    Regards,
    Nikita.

    Thread Starter Blackbam

    (@blackbam)

    Hi! Within block.php I have the following code:

    <section class="full-width-container" style="background-color:<?php
    echo
    get_lzb_meta('background-color'); ?>; padding: <?php
    echo
    get_lzb_meta('spacing'); ?>px 0; color: <?php
    echo
    get_lzb_meta('font-color'); ?>;">
    <div class="container">
    <div class="row">
    <InnerBlocks/>
    </div>
    </div>
    </section>


    This basically means it is inline code, isn’t it? When having two blocks in the same site, the background color changes for all elements within the site.

    Update: The problem seems to exist only for the color picker and only if using the “save in meta” option (not with $attributes). Furthermore it looks like it has nothing to do with the actually saved meta value, within the Gutenberg editor always adjusts it for all blocks (a “frontend” problem).

    • This reply was modified 1 year, 6 months ago by Blackbam.
    Plugin Author Nikita

    (@nko)

    Hi,

    Meta value is saved to the post data. So, when you add multiple blocks that work with the single meta, the value will be taken from post data, not from the individual block. This is why changing the value in one block changes in all blocks on the page.

    If you want to change the block colors or other things, you have to use block attributes (without the Save in Meta option). And your code will be like this:

    <div style="background-color: <?php echo $attributes['background-color'] || 'red'; ?>">Test</div>

    Regards,
    Nikita.

    Thread Starter Blackbam

    (@blackbam)

    Thanks, got it. Thought the meta value is per block, makes sense now.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Why do settings apply to all blocks within the same page?’ is closed to new replies.