Tuesday, November 9, 2010

Elements

Elements are HTML elements that you will use repeatedly within different views. You create the element then include it within your view code. They are stored within the /app/views/elements/ directory.

Create /app/views/elements/banner.ctp
<?php
echo "<div class=\"clear centerText\">
<script type=\"text/javascript\"><!--
google_ad_client = \"pub-9280152324836673\";
google_ad_slot = \"5630351766\";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script>
<script type=\"text/javascript\"
src=\"http://pagead2.googlesyndication.com/pagead/show_ads.js\">
</script></div>";
?>
Save and upload the file then edit /app/views/users/index.ctp Add the following line at the bottom of the file:
<?php echo $this->element('banner'); ?>
Save and upload the file then browse to http://drug-ed.com/ to verify it works. Since the element only exists on the /app/views/users/index.ctp page, it will only appear on that page. If you include the element on the /app/views/layouts/default.ctp page, it will display on every page.

Remove that line from the bottom of /app/views/users/index.ctp and add it to the "footer" div of the /app/views/layouts/default.ctp page.

No comments:

Post a Comment