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]