Parameter string issue

I have template variables for when an office opens and closes every day of the week. To select, you choose, for example, Monday Start and you have a drop down with a list of every half hour (ie 7:00 AM||7:30 AM||8:00 AM …

Within the template I have a snippet which I pass those times to, for an example 8:00 AM. When I try to explode on the colon “:” $x = explode(“:”,$variable), $x[0] returns “8:00 AM”, not 8. I tried to perform a substr command on the variable, and that will not work. Finally I did an if ($x == “8:00 AM”) { echo “True”; } else { echo “False” } and it returns False. I’ve checked for hidden characters but don’t see any.


Can you share more how you call this snippet (with the TV value as a property I presume) and the code of the snippet?

$today           = date("w", time()); // 0 = Sunday, 1 = Monday ...
$build_schedule  = '';
$schedule_temp   = '';
$open_time       = '';
$close_time      = '';
$timestamp_now   = '';
$timestamp_start = '';
$timestamp_end   = '';
$output          = '';
$full_hours      = '';

switch ($today) {
    case 0:
        $open_time = $sunstart;
        $close_time = $sunend;
    case 1:
        $open_time = $monstart;
        $close_time = $monend;
    case 2:
        $open_time = $tuestart;
        $close_time = $tueend;
    case 3:
        $open_time = $wedstart;
        $close_time = $wedend;
    case 4:
        $open_time = $thustart;
        $close_time = $thuend;
    case 5:
        $open_time = $fristart;
        $close_time = $friend;
    case 6:
        $open_time = $satstart;
        $close_time = $satend;

$timestamp_now = strtotime("now");
// $open_time = "8:00 AM" <-- This is how the variable is set
// echo "$open_time" <-- outputs "8:00 AM"
$test = explode(":",$open_time);
echo $test[0]; // <-- This will output "8:00 AM"

//$timestamp_start = timestamp($open_time);

//return '<p class="text-color-light text-3">' . $output . '</p>';

function timestamp($ts) {
    $build = date("m") . '/' . date("d") . '/' . date("Y") . ' ' . $ts;
    $return = strtotime($build);
    return $return;

So if landing.sundayam is a template variable and you’re running the snippet “Hours” directly in the template, you have to use [[*landing.sundayam]] (with the *) instead of the placeholder tag [[+landing.sundayam]] (with the +).


I will give that a shot in a moment and report back. So educate me, if you can, why the + doesn’t work. I say that because the value IS being passed.

[[*tvName]] is the MODX tag for a TV or a resource field.
[[+placeholder]] is the tag for a placeholder. To use a placeholder, it must be set first (e.g. in a snippet) before it can be used.

My guess is, that when your snippet “Hours” runs, the properties still have the values “[[+landing.sundayam]]” and that the placeholders haven’t been replaced with the actual values (like e.g. “8:00 AM”) yet.

My bad for not stating that. I do set the placeholders at the very top of the template.

        $modx->setPlaceholder('landing.sundayam', $resource->getTVValue('Working Hours-Sunday Start'));
        $modx->setPlaceholder('landing.sundaypm', $resource->getTVValue('Working Hours-Sunday End'));
        $modx->setPlaceholder('landing.mondayam', $resource->getTVValue('Working Hours-Monday Start'));
        $modx->setPlaceholder('landing.mondaypm', $resource->getTVValue('Working Hours-Monday End'));
        $modx->setPlaceholder('landing.tuesdayam', $resource->getTVValue('Working Hours-Tuesday Start'));
        $modx->setPlaceholder('landing.tuesdaypm', $resource->getTVValue('Working Hours-Tuesday End'));
        $modx->setPlaceholder('landing.wednesdayam', $resource->getTVValue('Working Hours-Wednesday Start'));
        $modx->setPlaceholder('landing.wednesdaypm', $resource->getTVValue('Working Hours-Wednesday End'));
        $modx->setPlaceholder('landing.thursdayam', $resource->getTVValue('Working Hours-Thursday Start'));
        $modx->setPlaceholder('landing.thursdaypm', $resource->getTVValue('Working Hours-Thursday End'));
        $modx->setPlaceholder('landing.fridayam', $resource->getTVValue('Working Hours-Friday Start'));
        $modx->setPlaceholder('landing.fridaypm', $resource->getTVValue('Working Hours-Friday End'));
        $modx->setPlaceholder('landing.saturdayam', $resource->getTVValue('Working Hours-Saturday Start'));
        $modx->setPlaceholder('landing.saturdaypm', $resource->getTVValue('Working Hours-Saturday End'));

So yes, the * does not pass a variable, but the + does. I just don’t understand the issue. It appears to be a string. I have check for hidden characters and there are none. But I can not do any type of string manipulation on that variable.

So why exactly are you doing this? And where?

If by any chance you set this placeholders in a snippet you call uncached, then call “Hours” also uncached (which you should do anyway) and use uncached placeholder tags ([[!+landing.sundayam]])

Yes, it’s probably the string “[[+landing.sundayam]]”.
Maybe log the values to confirm it → $modx->log(modX::LOG_LEVEL_ERROR, 'Value of $open_time is: ' . $open_time);

This is a website for a local government. There is the main index page, and then each department has its own landing page (but I do not want to make individual contexts for each department). Accordingly, on the main index page, and the sub-landing pages (for each department) are template variables that hold the data for what should be displayed in the footer, an alert which appears at the top of each page of a specific department, etc. When a page is displayed it first looks for the parent document which is of a specific template (sub-landing page or index) and pulls those template variables for its sub-pages.

Ahh!!! You are correct, the value being passed is the NAME of the template variable. How do I set it up to pass the actual value?

You have to make sure, that the placeholders are set before they are used.
The MODX parser first parses the cached tags, only then it parses the uncached tags.

For example in a case like this


[[useMyPlaceholder? &prop=`[[+somePlaceholder]]`]]

the snippet “useMyPlaceholder” runs before the placeholder [[+somePlaceholder]] is set in the snippet “setMyPlaceholder”.

Thanks halftrained. The snippet call to set the placeholders is the very first line in my template. Thanks to your help I have identified that the value being passed to my Hours snippet is the NAME of the template variable rather than the value. Now the questions is how to make, for example:


pass the value of “Closed” instead of passing “[[+landing.sundayam]]”

Is it cached or uncached?
If it’s uncached, then it doesn’t matter if it’s the first line or not.

1 Like
[[!Landing Page]]
<!DOCTYPE html>
<html lang="<?php echo Localization::activeLanguage() ?>">

	<body data-plugin-page-transition>
		<div class="body">

Uncached. [[!Landing Page]] is my snippet.

Woo Hoo. So I changed it to cached and it works as it should. I appreciate your help more than you will ever know!

So now you should change everything to uncached to make it really work.
(Your snippet “Hours” depends on the current time (time()), so it has to run uncached.)

Also maybe read this article (especially the “parsing order” section) to better understand how the MODX parser works.

Again, thank you! Sincerely.

Just out of curiosity, did you consider putting the HTML to display the times for a whole week in a single text TV, displayed with a single tag? That would probably decrease page-load time, since it would do the job with no code and no calculations. On the other hand, though, it would take up more screen real estate.

It’s an interesting case, because there are so many different ways to do it. My first thought was to put the snippet tag where where you want the value displayed, and get the desired TV value directly in the snippet by querying the modTemplateVarResource table (modx_site_tmplvar_contentvalues table), then just return the value. I’m not sure that’s any better than what you did.

Thank you for the feedback. Since the hours change depending on the department I am writing a script which first shows if they are open, opening soon, closing soon or closed and then grouping like hours together, so if Monday through Friday has the same hours it would show Mon-Fri - 8:00 AM - 5:00 PM to save real estate.

In that case, your method makes excellent sense.