Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7927977
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T19:36:18+00:00 2026-06-03T19:36:18+00:00

(Using ModX 1.0.5) When I execute my current snippet (see snippet below), it seems

  • 0

(Using ModX 1.0.5)

When I execute my current snippet (see snippet below), it seems to completely ignore the if(empty()) checks.
I have also tried with if($promoX == ''), also no luck.

<?php
    $promo1 = '[*sidepromotop*]'; // assets/images/promo1.jpg
    $promo2 = '[*sidepromobot*]'; // this variable is empty.

    if(empty($promo1) && empty($promo2)){
       echo '[!Ditto? &startID=`92` &depth=`1` &display=`2` &randomize=`1` &tpl=`Promo-Block-Styles`!]';
    }else{
       if(empty($promo1)){
          echo '[!Ditto? &startID=`92` &depth=`1` &display=`1` &randomize=`1` &tpl=`Promo-Block-Styles`!]';
       }else{
          echo '<div class="promo"><img src="'.$promo1.'" alt="" /></div>';
       }
       if(empty($promo2)){
          echo '[!Ditto? &startID=`92` &depth=`1` &display=`1` &randomize=`1` &tpl=`Promo-Block-Styles`!]';
       }else{
          echo '<div class="promo"><img src="'.$promo2.'" alt="" /></div>';
       }
    }
?>

The code above will for some reason display the following:

<div class="promo">
    <img src="assets/images/promo1.jpg" alt="">
</div>
<div class="promo">
    <img src="" alt="">
</div>

As you can see, even if the variable is empty, it apparently still treats it as not empty when I run it though my code.

I would really appreciate some insight on this, as I am very new to modx, and it is giving me such a headache!

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T19:36:29+00:00Added an answer on June 3, 2026 at 7:36 pm

    MODX tags such as [*sidepromotop*] are not parsed from within a snippet (it’s raw php), so in fact the empty() checks are working perfectly as you are passing them the unparsed tag as a string.

    What you need to do instead is make use of $modx->getTemplateVar() for retrieving the current document’s template variables:

    $promo1 = $modx->getTemplateVar('sidepromotop');
    

    Alternatively, you can pass them as parameters into your snippet call…

    [!mySnippet? &promo1=`[*sidepromotop*]` &promo2=`[*sidepromobot*]`!]
    

    …and they will be available as the variables $promo1 and $promo2 in your snippet code.

    *

    You should also use $modx->runSnippet() to execute Ditto from within the snippet, it will be much more efficient.

    $output = $modx->runSnippet('Ditto', array(
        'startID'   => 92,
        'depth'     => 1,
        'display'   => 1, 
        'randomize' => 1,
        'tpl'       => 'Promo-Block-Styles',
    ));
    return $output;
    

    Check out this wiki article for some great tips for creating snippets for MODX:
    http://wiki.modxcms.com/index.php/Creating_Snippets

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a website using modx evolution v1.0.2. The website that I have
I have recently set up a website using MODx Revolution. I am attempting to
Hello MODx developers, I am using MODx revolution. I have just transferred site from
I am using FormIt extra in Modx Revolution and I have an url like
I am using SimpleSearch snippet in Modx Revolution CMS for searching webpage content. Using
I am using MODx revolution and I have watched the video at: http://rtfm.modx.com/display/revolution20/Security I
I am using the Gallery Snippet on MODx Revolution 2.1.5. I am calling out
I'm using modx-2.2.0-pl2 (revo). Did a clean install without any error, but after login
I've been adding CMS functionality to a site using modx Evolution 1.0.2 . I've
Using C# for ASP.NET and MOSS development, we often have to embed JavaScript into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.