Fork me on GitHub

Smarty date range help please  Bottom

  • In the Content module I'm pulling in a dynamic image that uses a date range built in the URL like

    Code

    &bdate=20100429&edate=20100501


    The range I need for the dynamic content is today's date plus two days.

    So I've got a custom template in the /themes/mytheme/templates/modules/content/ folder with this code (URL trimmed down for clarity)

    Code

    <div>
    <!--[assign var='bdate' value=$smarty.now|date_format:"%Y%m%d"]-->
    <!--[assign var='edate' value=$bdate+2]-->
    <img src="/&bdate=<!--[$bdate]-->&edate=<!--[$edate]-->" width="750" height="250" />
    </div>


    This works fine except at the end of the month like today. It produces a non-existent date on the last two days of every month, since for instance today
    20100429
    + 2 = 20100431 (No such date as April 31)

    Is there a way I could change the Smarty variables to correct for this?



    edited by: damon, datetimebrief

    --
    Damon
    Catamaran Sailing at TheBeachcats.com
  • Note about the forum

    I'm getting a pop-up error box full of errors every time I post or edit a post. The post goes through, but freezes up the browser so it looks like nothing has happened.

    here's what I get, it's late so maybe someone is working on the forum.

    Code

    illegal JSON response:
    SyntaxError: syntax errorin
    <!DOCTYPE html
    public "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
    <head profile="http://www.w3.org/2005/10/profile">

    <title>Zikula Community :: Support at your fingertips</title>








     











    /* <![CDATA[ */ document.location.entrypoint="index.htm"; document.location.pnbaseURL="http://community.zikula.org/"; document.location.ajaxtimeout=25000; /* ]]> */











    <!--[if lte IE 7]>

    <![endif]-->
    </head>
    <!-- Home template -->
    <body id="bt_News" class="bt_home bt_2col bt_type_user bt_lang_en">
    <div id="layout_container">
    <div id="layout_container_inner">
    <div id="page_margins" class="bt_21 bt_nc bt_comm bt_func_main">
    <div id="page" class="">
    <!-- begin: #header -->
    <div id="header" class="floatbox">
    <div id="topnav">
    <div id="topnav_content">
    <!-- start: skip link navigation -->
    <a class="skip" href="#navigation" title="Skip link">Skip to the navigation</a><span class="hideme">.</span>
    <a class="skip" href="#content" title="Skip link">Skip to the content</a><span class="hideme">.</span>
    <!-- end: skip link navigation -->
    <a href="http://zikula.org" id="topbar_home">&nbsp;</a><a href="http://community.zikula.org" id="topbar_community" class="topbar_selected">&nbsp;</a><a href="http://community.zikula.org/module-Extensions.htm" id="topbar_addons">&nbsp;</a><a href="http://blog.zikula.org" id="topbar_blog">&nbsp;</a><a href="http://demo.zikula.org" id="topbar_demo">&nbsp;</a><a href="http://code.zikula.org" id="topbar_code">&nbsp;</a>
    </div>
    </div>
    <a href="http://community.zikula.org/"><img src="/themes/community/images/logo.gif" class="logo" alt="logo" width="283" height="72" /></a>
    <h1><a href="http://community.zikula.org/" title="Go to the homepage">Zikula Community</a></h1>
    </div>
    <!-- end: #header -->
    <!-- begin: main navigation #nav -->
    <div id="nav">
    <a id="navigation" name="navigation"></a>
    <!-- skiplink anchor: navigation -->
    <!-- Menu based upon http://www.cssplay.co.uk/menus/pro_dropx.html --><div id="nav_cssplaypro"><div id="nav_edge_left" class="nav_edge float_left"></div><div id="nav_edge_right" class="nav_edge float_right"></div><div class="side-header"><form id="search" onsubmit="searchbox()" method="post" action="module-Search-search.htm"><div id="search_all"><label for="search_question" class="overlabel">Search ...</label><input id="search_question" type="text" name="q" title="Search" value="" tabindex="1"/>  <input type="hidden" name="overview" value="1" />
    <input type="hidden" name="bool" value="AND" />
    <input type="hidden" name="active_ezcomments" value="1" />
    <input type="hidden" name="active_Extensions" value="1" />
    <input type="hidden" name="active_Dizkus" value="1" />
    <input type="hidden" name="active_news" value="1" />
    <input type="hidden" name="active_users" value="1" />
    <input id="search_submit" type="image" alt="Search" src="themes/community/images/design/common/nav_search.gif" /></div></form></div><div class="side-msgdata"><a href="/module-Messages.htm">&nbsp;</a></div><ul class="cssplay_prodrop"><li class="current"><a class="top" href="http://community.zikula.org/"><span>Home</span></a></li><li><a class="top" href="#"><span class="down">Use Zikula!</span><!--[if gte IE 7]><!--></a><!--<![endif]--><!--[if lte IE 6]><table><tr><td><![endif]--><ul class="drop"><li><a class="fly" href="http://zikula.org/CMS/About-Zikula/">About Zikula<!--[if gte IE 7]><!--></a><!--<![endif]--><!--[if lte IE 6]><table><tr><td><![endif]--><ul><li><a href="http://zikula.org/CMS/Features">Features</a></li><li><a href="http://zikula.org/CMS/Foundation-and-Steering-Committee/">Zikula Software Foundation</a></li><li><a href="http://zikula.org/CMS/Press/">Press</a></li></ul><!--[if lte IE 6]></td></tr></table></a><![endif]--></li><li><a class="fly" href="http://community.zikula.org/module-Forum-main-viewcat-12.htm">Connecting Zikulans<!--[if gte IE 7]><!--></a><!--<![endif]--><!--[if lte IE 6]><table><tr><td><![endif]--><ul><li><a href="http://community.zikula.org/module-Forum-main-viewcat-12.htm">Community forum</a></li><li><a href="http://community.zikula.org/module-Pages-display-pageid-5.htm">Our mailing list</a></li><li><a href="irc://irc.oftc.net/zikula">IRC channel</a></li><li><a href="http://twitter.com/TheZikulan">The Zikulan (Twitter Feed)</a></li></ul><!--[if lte IE 6]></td></tr></table></a><![endif]--></li><li><a href="http://zikula.org/CMS/International-Communities/">International communities</a></li><li><a href="http://community.zikula.org/module-GoogleMap.htm">Users Map</a></li><li><a href="http://zikula.org/infopages/Case-Studies/">Site showcase</a></li><li><a href="http://zikula.org/CMS/Hosting/">Zikula Hosting</a></li><li><a href="http://zikula.org/CMS/Donate-to-Zikula/">Donate to Zikula</a></li><li><a href="http://zikula.org/CMS/Contact-Us/">Contact the team</a></li></ul><!--[if lte IE 6]></td></tr></table></a><![endif]--></li><li><a class="top" href="http://community.zikula.org/module-Extensions-view-ot-distribution.htm"><span class="down">Downloads</span><!--[if gte IE 7]><!--></a><!--<![endif]--><!--[if lte IE 6]><table><tr><td><![endif]--><ul class="drop"><li><a class="fly" href="http://community.zikula.org/module-Extensions-view-ot-distribution.htm">Common distributions<!--[if gte IE 7]><!--></a><!--<![endif]--><!--[if lte IE 6]><table><tr><td><![endif]--><ul><li><a href="http://community.zikula.org/module-Extensions-display-ot-distribution-distributionid-7.htm">Blog</a></li><li><a href="http://community.zikula.org/module-Extensions-display-ot-distribution-distributionid-8.htm">Communities</a></li><li><a href="http://community.zikula.org/module-Extensions-display-ot-distribution-distributionid-4.htm">Content management</a></li><li><a href="http://community.zikula.org/module-Extensions-display-ot-distribution-distributionid-5.htm">ECommerce</a></li><li><a href="http://community.zikula.org/module-Extensions-display-ot-distribution-distributionid-6.htm">Enterprise</a></li></ul><!--[if lte IE 6]></td></tr></table></a><![endif]--></li><li><a href="http://community.zikula.org/module-Extensions-view.htm">Create your distribution</a></li><li><a class="fly" href="http://code.zikula.org/core/wiki/downloads">Zikula Core-only<!--[if gte IE 7]><!--></a><!--<![endif]--><!--[if lte IE 6]><table><tr><td><![endif]--><ul><li><a href="http://code.zikula.org/core/wiki/downloads">Stable release</a></li><li><a href="http://code.zikula.org/core/browser/development">SVN-development</a></li><li><a href="http://code.zikula.org/core/downloads">Legacy releases</a></li></ul><!--[if lte IE 6]></td></tr></table></a><![endif]--></li><li><a class="fly" href="http://community.zikula.org/module-Extensions.htm">Extensions<!--[if gte IE 7]><!--></a><!--<![endif]--><!--[if lte IE 6]><table><tr><td><![endif]--><ul><li><a href="http://community.zikula.org/module-Extensions-view-comptype-1.htm">Modules</a></li><li><a href="http://community.zikula.org/module-Extensions-view-comptype-2.htm">Themes</a></li><li><a href="http://community.zikula.org/module-Extensions-view-comptype-3.htm">Blocks</a></li><li><a href="http://community.zikula.org/module-Extensions-view-comptype-4.htm">P


    --
    Damon
    Catamaran Sailing at TheBeachcats.com
  • Having the same error when trying to create a new post - illegal json...
  • I dont' know how to do this in smyrty, but you can write your own little Smarty modifier.
    Maybe this is what you are searching for: http://bytes.com/topic/php/answers/857706-addition-subtraction-smarty
  • agreed that a Smarty modifier would be easiest.

    have the modifier accept the date string
    create a datetime object from the formatted string
    modify the datetime object to add two days
    return new formatted string.

This list is based on users active over the last 60 minutes.