Forums » Display Simple Pages entry in index.php

RSS feed for this topic

Info

  • Posted in Plugins
  • Started 1 year ago by nathandirks
  • 5 posts by 2 users
  • Latest reply from nathandirks
  1. I'm looking for a way that other back-end users/contributors can edit a block of text on the index.php file without modifying the source code.

    In specific, I'm wondering if an entry from the Simple Page Plugin Text box field can be called to display on the index.php and other .php files?

  2. Nathan, that's a very interesting idea! We currently do not have a helper function to do this, but if you know a little PHP you can hack it like this:

    Change SimplePages/views/page/show.php to look like this:

    <?php if (isset($wrapit) && $wrapit == false) : ?>
    <?php echo eval('?>' . $page->text); ?>
    <?php else: ?>
    <?php head(array('title' => html_escape($page->title), 'bodyclass' => 'page', 'bodyid' => html_escape($page->slug))); ?>
    <div id="primary">
        <h1><?php echo html_escape($page->title); ?></h1>
        <?php echo eval('?>' . $page->text); ?>
    </div>
    <?php echo foot(); ?>
    <?php endif; ?>

    In your index.php page, add this code to see the a simple page with the slug "about":

    <?php
    
        	function getPageByPageSlug($pageSlug) {
                    $table = get_db()->getTable('SimplePagesPage');
                    $select = $table->getSelect();
                    $select->where('s.slug = ?', array($pageSlug));
                    $pages = $table->fetchObjects($select);
            		if ($pages) {
            		    $page = $pages[0];
            		    return $page;
            		} else {
            		    return null;
            		}
        	}
    
        	$pageSlug = 'about';
        	$page = getPageByPageSlug($pageSlug);
        	if ($page) {
        	    echo $this->partial('page/show.php', array('page' => $page, 'wrapit' => false));
        	}
    ?>

    Of course hacking SimplePages like this will mean that if you upgrade SimplePages, you'll need to replace the page/show.php page again.

    Let me know if this helps. I'll see if we can add a helper function to make this easier in the next version of SimplePages.

  3. Thanks Will! This works like a charm. Exactly what I needed.

    Now I'm wondering if there's a way to remove the About page (in this example) from the dynamic nav menu so the content doesn't double up, while still allowing "normal" Simple Pages (simple pages that aren't called into .php files) to display dynamically in the nav menu?

  4. Have you tried editing a simple page and unchecking the "Link to this page on the public navigation?" checkbox?

  5. Geez. Right under my nose. Thanks.

Reply

You must log in to post.