Quantcast

Joel Nagy .com

web technology is a way of life

MODx Math

Just found my self needing to implement an <iframe> into a MODx site, and since I wanted to have the <iframe> be part of the template I felt it would be best to have the src, width and height be template variables making the <iframe>’s appearance based on the content and not fixed. For my particular needs I was wrapping everything in a <table> that then needed to have a width slightly larger than the <iframe>. For this I came up with a simple snippet that evals a little equation forcing it to an integer to be safe:


<?php
// eg: [[math?math=[*iframeWidth*]+34]]

if (isset($math)) {
     eval("\$math = (int) ". $math .";");
     echo $math;
} else
     echo "0";
?>

So if [*iframeWidth*] is set to 550 and I have <table width=”[[math?math=[*iframeWidth*]+34]]“> in the template then the rendered HTML will be <table width=”584“>

Reblog this post [with Zemanta]
  • 0 Comments
  • Filed under: Code
  • We officially launched a new version of our website for kb.com which is focused on the true core of any company, the people. Sure we have the typical statements about what we do and a portfolio of the work we’ve done, but the bulk of the site is a profile for every employee, here’s mine.  Our team here worked very, very hard to get this up and running.  The whole site is built on MODx as a CMS for the primary reason that it easily allows for pages to be content managed by anyone and rendered as XML, and that it has an extremely easy interface to hand code PHP (with what they call snippets) tp allow for all sorts of dynamic functionality from the server side.  The front end is built with Adobe Flex in combination with jQuery which handles deep-linking, proper autosizing of the page, loading the SWF and all of the tracking.

    The site required a lot of digging into MODx to filter and deliver all of the data to Flex.  I made a number of snippets and modified quite a few, especially ListIndexer, to provide XML output that drove the front-end.  In order to populate the site, I also made a number of custom SQL scripts (converted via Regular Expressions from an Excel document) that pushed content into many of the tables.  The hardest part here was populating all of the template variables; which required figuring out the variable mappings.  In the end the site has 6 sitemap files totalling in 400+ URLs all of which are deep-linkable.

    I don’t think this site could have been put together without MODx, no other decent (and free opensource) CMS has the capabilites to handle XML output and simple server side scripting access.

    The team that helped bring this site together is Ro Pulliam (an amazing Flex freelancer), Anthony Cafaro, Tara Milone, Megan O’Connor, Heather Martin, and Jason McKim.

    Reblog this post [with Zemanta]
  • 0 Comments
  • Filed under: General
  • MODx: data passing between snippets

    I’ve found a little problem with MODx and transferring data to a snippet and using it in a string comparison.  The issue arises when you call a snippet from within a page (in the [*content*] portion).  There is also an issue when passing a MODx var in a snippet parameter.  In order to overcome this issue, I’ve needed to create two snippets, one called within the template and another that can be called in the text of [*content*] and get the data from the first snippet.

    1. Create a snippet called [[setup]] with this code:

    $modx-vars = Array();
    $modx->vars['alias'] = $alias;
    

    2. Create another snippet called [[nav]] which would have code like this that would give a class to a navigation link for example:

    $alias = $modx->vars['alias'];
    echo $alias == 'index'? ' class="current"': '';
    

    3. Then we’ll need a template with this code:

    [[setup?alias=[*alias*]&done]]
    [*content*]
    

    Note: In the call to [[setup]] we end with &done since the triple end brackets ] cause a problem of their own.

    4. Finally create a page with this content:

    [[nav]]
    

    Now you can use the $modx->vars array to pass any data you need from one snippet to others when you need to use that data for actual string comparison, manipulation or usage that would otherwise only be accessible after MODx performs a php eval.

    Reblog this post [with Zemanta]
  • 3 Comments
  • Filed under: Code
  • In Other News...