There are so many essential things you simply can't do with EE; this is one I'm having issues with.

What I want to do:

  1. Use AJAX to GET a template while sending data via the URL segments.

    • In the ajax, we're preformatting integers to strings so that all single digit integers get preceding zeros (e.g.: 1 becomes 01 by using JS var seg1 = '' + {segment_1}, etc.).

    • We send these integers in date format to a template /.../.../.../01/03/2014/

  2. On our template called via AJAX we embed another template using those values

    • However, during the AJAX request all preceding zeros are truncated :p

So doing something like

{embed="calendar/event_landing" range_start="{segment_4}-{segment_5}-{segment_6}" range_end="{segment_4}-{segment_5}-{segment_6}"}`

will only represent the above example as /.../.../.../1/3/2014/ with no zeros.

To circumvent this oddity, I thought I'd try to do something like

// Pad the segments with zeros because the preceding zeros on single digit segments are truncated during the $.ajax(...) GET request.
if (strlen($seg4 == 1) {
    str_pad($seg4, 2, '0', STR_PAD_LEFT);

if (strlen($seg5 == 1) {
    str_pad($seg5, 2, '0', STR_PAD_LEFT);

then try something as audacious as it is ludicrous:

 {embed="calendar/event_landing" range_start="<?php echo $seg4; ?>-<?php echo $seg5; ?>-{segment_6}" range_end="<?php echo $seg4; ?>-<?php echo $seg5; ?>-{segment_6}"}

While that doesn't work at all (and really shouldn't anyway) I think it explains what I'm trying to do: pass the newly zero-padded integers to the embedded calendar/event_landing template where I'm using their values as follows using the Solspace Calendar plugin:

{exp:calendar:cal date_range_start="{embed:range_start}" date_range_end="{embed:range_end}" pad_short_weeks="n"}

In case it wasn't implied, the Solspace Calendar uses EE date formatting (as found here: http://www.solspace.com/docs/calendar/date_formatting/), and will not accept single digit numbers. If single digit numbers are passed to it, then it causes an error and instead of throwing it, it simply reverts to the value of the current day.

(The beginning of this rabit-hole inquiry started here one day ago: Solspace Calendar embed range not registering)

1 Answer 1


Why not to use this?

{if segment_4 < 10}0{/if}{segment_4}

There's a lot of things the template language of EECMS can't, but... It is just a template language.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.