Menu

The TPage class: adding content

You can add content to a TPage object right when you create it; it is the second parameter, coming after the page title. Ex.:

<?php
$page = TPage('Page Title', 'Page content');

Instead of that, you can use the regular add() function to add content to the page. Ex.:

<?php
$page = TPage('Page Title');
$page->add('Page content');

A page will automatically generate a container div element with its id set to "main". Any content added to a page will actually be added to the "main" div in that page. So, in the previous example, the <body> element of the page will be like this:

:::html
<body>
    <div id="main">
    Page content
    </div>
</body>

You can easily create other div containers and add content to them instead of adding to the "main" div of the page. To do so, you just have to add one parameter to the add() function, corresponding to the id of the div you want to create. So, if you do this:

<?php
$page = TPage('Page Title');
$page->add('Some content.');
$page->add('Something else.', 'another');

The result will be:

:::html
<body>
    <div id="main">
    Some content.
    </div>
    <div id="another">
    Something else.
    </div>
</body>

Without you needing to declare and include the div by hand.

You can configure this behaviour by defining two constants before including the library:

  • GJ_AUTOMAIN (true/false) defines whether an automatic div container will be created or content will be added directly to the body element of the page.
  • GJ_PAGECONTAINERTYPE defines the type of the element to be used as a container; the default is div.
Posted by panglossa 2013-04-10 | Draft

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.