• Resolved RPittam

    (@rpittam)


    I have a page where I call a snippet from a Gutenberg shortcode block for the top section of the page which creates the titles and tabs. Then I have 2 more Gutenberg blocks which call both a Spectra Image gallery then Nextgen gallery respectively. Then underneath that have a further Gutenberg block which calls another php snippet, to create a further set of tabs at the bottom- not seen on the link as the snippets won’t compile. With just the tabs creation it compiles active no problem, but when I try to call another snippet within this snippet, it fails with a ‘We encountered an error activating your snippet, please check the syntax and try again. Error message: syntax error, unexpected identifier s, expecting , or ;’ error. The snippet is fairly straightforward but calling a ‘nested’ snippet seems to break it. This is the bit of the snippet code that fails –

    // ----------------------------

    // Bottom Tabs PHP Snippet

    // ----------------------------

    // Maps snippet ID

    $maps_snippet_id = "71216";

    ?>

    <style>

    .moth-tabs-bottom { margin-top: 20px; }

    .tab-buttons-bottom { list-style: none; padding: 0; display: flex; border-bottom: 2px solid #ccc; margin-bottom: 15px; }

    .tab-buttons-bottom li { padding: 10px 20px; cursor: pointer; border: 1px solid #ccc; border-bottom: none; margin-right: 5px; border-radius: 5px 5px 0 0; background: #f7f7f7; }

    .tab-buttons-bottom li.active { background: #fff; font-weight: bold; }

    .tab-content-bottom { display: none; border: 1px solid #ccc; padding: 15px; border-radius: 0 5px 5px 5px; background: #fff; }

    .tab-content-bottom.active { display: block; }

    </style>

    <div class="moth-tabs-bottom">

        <!-- Tab buttons -->

        <ul class="tab-buttons-bottom">

            <li class="active" data-tab="maps">Maps</li>

            <li data-tab="charts">Charts</li>

            <li data-tab="data">Data</li>

        </ul>

        <!-- Maps tab -->

        <div id="maps" class="tab-content-bottom active">

            <?php

            // Safely call the Maps snippet

            echo do_shortcode('[wpcode id="' . $maps_snippet_id . '"]');

            ?>

        </div>

        <!-- Charts tab -->

        <div id="charts" class="tab-content-bottom">

            <p>Charts content goes here.</p>

        </div>

        <!-- Data tab -->

        <div id="data" class="tab-content-bottom">

            <p>Data content goes here.</p>

        </div>

    </div>

    <script>

    document.addEventListener("DOMContentLoaded", function() {

        const tabs = document.querySelectorAll(".tab-buttons-bottom li");

        tabs.forEach(function(button){

            button.addEventListener("click", function(){

                const tab = button.getAttribute("data-tab");

                tabs.forEach(btn => btn.classList.remove("active"));

                document.querySelectorAll(".tab-content-bottom").forEach(tc => tc.classList.remove("active"));

                button.classList.add("active");

                document.getElementById(tab).classList.add("active");

            });

        });

    });

    </script>

    The page I need help with: [log in to see the link]

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter RPittam

    (@rpittam)

    forgot to mention I currently use Spectra tabs blocks for both the top tabs set and the bottom set and they work ok, generally, and I can call snippets from within these tabs as they are just Gutenberg blocks. However, the spectra tabs blocks break periodically so I wanted a more coded solution not relying on so many Gutenberg blocks and giving my 1700 pages a more central control rather than 1700 possible issues.
    this is a working current spectra tabs blocks page – so you can see where it has called snippets for a map, charts and data table ok –

    https://www.derbyshiremoths.org/1979-lime-hawkmoth-sphingidae-mimas-tiliae/

    thanks

    Richard

    Plugin Support markomiljanovic

    (@markomiljanovic)

    Hi @rpittam,

    The PHP snippet you’ve provided for the appears to be syntactically correct on its own. The error message you’re seeing most likely originated from the piece of code that was executed just before it.

    When your page loads, WordPress (and the snippet plugin) processes the code from your different snippets in sequence. If a preceding snippet has a small, unclosed syntax error—such as a missing semicolon (;), an unclosed bracket ), or an unclosed quote "—it can cause the PHP parser to become confused. The parser then continues reading until it hits the next piece of code. It tries to make sense of it but fails because of the leftover error from the previous snippet, and it incorrectly reports the error on your new, perfectly valid code.

    I would suggest checking the WPCode snippet with the ID 71216 for potential issues as described above, since this is the one used inside this snippet you sent us.

    Please reach out using the form at https://wpcode.com/contact if you want to share more details privately about your setup so that we can try to replicate the issue.

    Thread Starter RPittam

    (@rpittam)

    Thanks – snippet ID 71216 which i was trying to call is a very large php snippet, 1249 lines long. It uses leaflet to draw a map with several overlays of data and geojson layers – it works fine and has done for a good while now. My question really, was , is it ok to do as i have done – calling another snippet from within html code of another snippet? – it would seem the answer is yes, but for some reason this called snippet 71216 introduces something that the wpcode parser does not like or cannot parse….. i can send you the 71216 snippet, but i suspect that is not within my ‘free’ support remit… any tips or clues as to what to look for in the called snippet, that will trigger these syntax error, unexpected identifier s, expecting , or ;’ errors? Thanks. richard.

    <?php        // Safely call the Maps snippet        echo do_shortcode('[wpcode id="' . $maps_snippet_id . '"]');        ?>

    I got an email notification because I’m watching “leaflet”. And I use this plugin too.

    Try similar:

    <?php

    $text = code of the Bottom Tabs PHP Snippet up the do_shortcode line;
    $text = $text . do_shortcode('[wpcode id="' . $maps_snippet_id . '"]');
    $text = $text . the remaining code from Bottom Tabs PHP Snippet;
    echo $text;
    Plugin Support markomiljanovic

    (@markomiljanovic)

    @rpittam,

    Thanks for the update.

    There aren’t any problems without setup. You can execute one snippet from another just as you did.

    You don’t have to check the whole code in the code snippet, if you do have such issues in the middle of the snippet, that would prevent execution for the rest of the code, which is not the case because you stated that the snippet is working.

    It could be because this snippets is using a closing PHP tag at the end of the code (?>) which can interfere with execution of other snippets due to the way we executed snippets to track errors more precisely.

    Can you please check it and if there is a closing PHP tag at the end of the snippet, just remove it and check if the issue is resolved?

    Although there are limitations to free support, if the issue remains, we’re happy to help you identify what’s causing the problem, Please feel free to reach out via our contact form https://wpcode.com/contact with the exported snippet attached, and we’ll do our best to assist you.

    Thread Starter RPittam

    (@rpittam)

    at the moment I will have to mark this as resolved – too complicated to move forward- will stick with spectra tabs block and Gutenberg code snippet calls.
    thanks

Viewing 6 replies - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.