Skip to content

Instantly share code, notes, and snippets.

@Aaron3
Last active December 21, 2015 17:39
Show Gist options
  • Save Aaron3/6342054 to your computer and use it in GitHub Desktop.
Save Aaron3/6342054 to your computer and use it in GitHub Desktop.
For a single item (say, a single article)
In your Data:
<?php
$data = array('title' => 'My Single Title', 'content' => 'My Single Content');
?>
In your View:
<article>
<h1><?php echo $data['title'];?></h1>
<p><?php echo $data['content'];?></p>
</article>
For Multiple item (say, a recent post list)
In your Data:
<?php
$data_array[] = array('title' => 'My First Title', 'content' => 'My First Content', 'link' => 'http://google.com');
$data_array[] = array('title' => 'My Second Title', 'content' => 'My Second Content', 'link' => 'http://google.com');
$data_array[] = array('title' => 'My Third Title', 'content' => 'My Third Content', 'link' => 'http://google.com');
$data_array[] = array('title' => 'My Fourth Title', 'content' => 'My Fourth Content', 'link' => 'http://google.com');
?>
In your View:
<ul>
<?php foreach($data_array as $data){ ?>
<li>
<a href="<?php echo $data['link'];?>"><?php echo $data['title'];?></a>
<p><?php echo $data['content'];?></p>
</li>
<?php } ?>
</ul>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment