You are logged in.
{{ else }}You are not logged in.
{{ endif }} [ 79 ] www.it-ebooks.info Building a Website with PyroCMS There are, of course, a number of other ways you can use tags in PyroCMS, but this covers the basics If you want to learn more about tags and other advanced tag syntax, you can find more in the PyroCMS documentation at http://www.pyrocms com/documentation Adding theme partials To make out theme layout more efficient, we're going to make use of theme partials Partials are partial layout files in PyroCMS, and they allow you to break layouts into reusable sections These sections can then be loaded by different layout files This keeps you from typing the same code (header, footer and so on.) into multiple layout files In the most basic way, we can break our layout into partial files, header.html, default.html, and footer.html Create each of these files in your theme folder, adding the header.html and the footer.html files into the respective partials directory You can then include those partial files into your default layout file by using a tag shown as follows: {{ theme:partial name="partialname" }} Now that we are making use of partials, the following is an example of what each of our layout files should include: • Our header.html file, found at addons/shared_addons/themes/[mytheme-name]/views/partials/, should contain the following chunk of code formerly found in our default layout file: {{ template:title }} {{ template:metadata }} {{ theme:favicon file="favicon.png" }} {{ theme:css file="style.css" }} {{ theme:js file="site.js" }} {{ theme:image file="logo.jpg" alt="Your Happy Logo" }} {{ navigation:links group="header" }} [ 80 ] www.it-ebooks.info Chapter • Our default.html file, found at [your-theme]/views/layouts/default.html should now contain the following code: {{ theme:partial name="header" }} {{ template:title }} {{ template:body }} {{ theme:partial name="footer" }} • Our footer.html file, found at addons/shared_addons/themes/[mytheme-name]/views/partials/, should now contain the following code formerly found in the default layout file: See how, when using partials, all the necessary files get included into the default layout file? This is a common way to introduce efficiencies into your template code so that, as a developer, you save time, which is what PyroCMS is all about Now that we have our basic theme put together, we can add content to our website You can this by using the Pages module in the system (in the control panel) Two things we'll add our website, beyond basic page content, are a contact form and stream data Adding a contact form A contact form is a basic feature of many, many websites This feature comes built into PyroCMS, and can be added to any page in the system simply because it is a plugin tag you add to your website The tag that creates this form is more complicated than most tags, but it makes simple work out of building and validating a contact form The following tag is a simple example of a tag that generates a contact form: {{ contact:form name = "text|required" email = "text|required|valid_email" subject = "dropdown|required|hello=Howdy| support=Support Ticket" message = "textarea|required" attachment = "file|jpg|png|zip" }} [ 81 ] www.it-ebooks.info Building a Website with PyroCMS {{ name }} {{ email }} {{ subject }} {{ message }} {{ attachment }} {{ /contact:form }} This contact form generates five input fields for a user These inputs are name, email, subject, message, and attachment Each parameter on this form tag can take a pipe-delimited set of values For most inputs, this pipe-delimited value follows a specific format This first value in the delimited string is, for example, the name of the input field The second delimited value determines whether or not the form input should be required for the user The third delimited value can either be an extension of validation rules or another set of delimited values that determine the options included in a dropdown The subject field, for example, will be output as a dropdown of values that include Howdy and Support Ticket These forms follow the form validation patterns used by CodeIgniter If you are unfamiliar with how forms get validated by CodeIgniter, you can refer CodeIgniter's User Guide for form validation documentation at http://ellislab.com/codeigniter/user-guide/ libraries/form_validation.html Adding stream data to your website We covered streams in the previous chapter of this book Building upon our efforts there, we are going to reuse the employees stream we built in that chapter That stream is a directory of people's names and phone numbers, one that can be output to a website To build that stream, we used the Streams module that comes built into the professional version of PyroCMS If you didn't follow the steps put together in Chapter 6, Using PyroCMS Streams, then you'll want to create a new stream of data called employees in PyroCMS using the Streams module We're going to take that stream, embed it into a page so that it can be seen by a user Then, taking it a step further, we're going to build a details page for a single stream entry This type of interaction, as I'm sure you know, is very common among websites First, let's take a look at the stream tag that's going to loop through our employee entries and output the values from our database, shown as follows: {{ streams:cycle stream="employees" limit="5" }} {{ entries }}{{ name }}
{{ /entries }} {{ /streams:cycle }} [ 82 ] www.it-ebooks.info Chapter This code acts exactly like a for loop in PHP, looping over our data You can add this streams tag to any page you create using the Pages module In the case of this specific example, let's create a page called Employees that will list all of the employee entries in the stream: We'll modify our stream tag a little bit by adding a link around the name variable, so that each record in the stream links to the single, detailed stream entry Later, we'll embed the code for that single entry on a nested page The code we'll need for our details page is very similar to the code we put on the base employees page, but it uses a URL value and the id parameter to limit the data returned to the user, shown as follows: {{ streams:cycle stream="employees" limit="5" }} {{ entries }}{{ name }}
{{ /entries }} {{ /streams:cycle }} As part of the details page, you can display the phone number we've entered for each entry in the employees stream, as shown in the following code sample We'll take the following code and add it to a page that is nested underneath our base employee page in the Pages module: {{ streams:cycle stream="employees" id="[segment_3]" limit="1" }} {{ entries }} {{ name }}{{ phone }}
{{ /entries }} {{ /streams:cycle }} [ 83 ] www.it-ebooks.info Building a Website with PyroCMS If however, you try to get these pages to connect without doing one more step, you'll see that is doesn't work You'll be given a "404 page not found" error To get all of our URLs to line up correctly, we're going to define a custom URL route in PyroCMS that will make this common/details page setup work, which will then appear as shown in the following screenshot: Defining a custom route Building a custom route in PyroCMS is quite easy to In a way, though, adding this route to the system is modifying core code that could be wiped out with future updates to the system, so take care of these routes The file where you'll add your custom route is located within your PyroCMS project files, shown as follows: system/cms/config/routes.php To accommodate the employee/detail page we have created, you need to add the following route to your routes.php file: $route['employees/detail/(:any)'] = 'pages/view/employees/detail'; This route essentially makes the ID number that appears in your link to the details page, the parameter with which we can make a query against the database Once you have this route installed, you should be able to link from an employee record in your stream to a detailed employee record page [ 84 ] www.it-ebooks.info Chapter Summary What I've shown you in the last few pages of this book are the essential steps to getting a website running using PyroCMS We covered getting the system installed, creating a theme, and using streams to help power database driven content on your website What I hope you've learned is that it doesn't take much effort to start building a smart website on PyroCMS Because of its ability to leverage programming patterns, an easy-to-use PHP framework, and wicked fast theme development workflow, PyroCMS, as I hope you've seen, is an extremely well-outfitted system that's ready to be used on any website project [ 85 ] www.it-ebooks.info www.it-ebooks.info Index A add-ons option, control panel 22 admin controllers 46 assets, stream data entry form 73 B backend input form 66 basic tag 54 C CodeIgniter about 6, 37 URL, for info common variables, Streams plugin 67 contact form about 81 adding 81, 82 content management systems content option, control panel 20 controllers adding, to modules 46, 47 control panel modules add-ons 22 content 20 data 21 profile 23 settings 22 structure 20 users 21 control panel, PyroCMS accessing 17, 18 dashboard 19 default language, selecting 23 layout 19 navigation 19 CSS tab, page creation form 29 cURL about URL custom data page, creating with 33, 34 custom error message, stream data entry form 73 custom page type fields creating 31-33 custom route defining 84 custom success message, stream data entry form 73 custom theme creating 76, 77 D dashboard 19 data displaying 67 data option, control panel 21 data stream module 61 date filter, Streams plugin 68 default columns for streams 65 default language selecting 23 details.php file code 44, 46 Drupal DRY protocol 56 www.it-ebooks.info E e-mail notifications, stream data entry form 73 entry looping, Streams plugin 68 F features, modules 38 fields assigning, to streams 64 creating, for streams 63, 64 ordering, on streams 65 folder structure, modules 38 folder structure, themes 49, 76 modules about 38 controller, adding to 46, 47 creating, in PyroCMS 39 features 38 folder structure 38 module view overloading 60 multiple layouts for tags, in templates 58 MySQL about URL, for info N namespaceing nested variables, Streams plugin 70 G GD2 GitHub PyroCMS, downloading from O H P help() method 43 HTTP web server 6, page about 25 creating, in PyroCMS 27 creating, with custom data 33, 34 Page Content tab, page creation form 28 page creation form CSS tab 29 Meta Data tab 28 Options tab 29 Page Content tab 28 Page Details tab 28 Script tab 29 Page Details tab, page creation form 28 Pages module 26 page tree 26 page types about 25, 29, 61 creating 30, 31 custom page type fields, adding 31-33 page, creating with custom data 33, 34 versus layouts 57 pagination feature, Streams plugin 70 Options tab, page creation form 29 I index() method 47 info() method 40, 41 install() method 41, 42 L layout file creating 78, 79 layouts displaying, for mobile 59 versus page types 57 Lex parser tags 31, 35, 56 loop cycle, Streams plugin 68 M Meta Data tab, page creation form 28 mobile layouts 59 Model-View-Controller (MVC) [ 88 ] www.it-ebooks.info parameters, Streams plugin about 69 date_by 69 day 69 disable 69 exclude 69 exclude_called 69 include 69 include_by 69 limit 69 month 69 namespace 69 no_results 69 offset 69 order_by 69 partial 69 show_past 69 show_upcoming 69 sort 69 stream 69 where 69, 70 year 69 PHP PHP 5.2 plugin.php file 36 plugins about 35 building, for PyroCMS 36, 37 in modules 47 tags 35 URL, for documentation 38 prerequisite methods, PHP class help() method 43 info() method 40, 41 install() method 41, 42 uninstall() method 43 upgrade() method 43 profile option, control panel 23 public controllers 46 PyroCMS about Community version, features Community version versus Professional version 10 control panel 17 downloading downloading, from GitHub installation 75 installation process, troubleshooting 14 modules, creating 39 page, creating 27 platform support 6, plugins, building 36, 37 Professional version, features 10 software requisites 5, URL, for downloading URL, for forums 14, 76 URL, for installation guide 14 PyroCMS installer about 5, 10 steps 11-14 PyroStreams 61 PyroStreams module 10 S Script tab, page creation form 29 settings option, control panel 22 software requisites, PyroCMS about CodeIgniter cURL GD2 HTTP web server 6, MySQL PHP stream data adding, to website 82, 83 stream data entry form about 71 assets 73 building 71, 72 custom error message 73 custom success message 73 e-mail notifications 73 streams about 61 creating 62, 63 fields, assigning to 64 fields, creating for 63, 64 fields, ordering on 65 Streams module about 61 obtaining 61 [ 89 ] www.it-ebooks.info URL, for purchasing from PyroCMS add-on store 61 Streams plugin about 67 common variables 67 date filter, adding 68 entry looping 68 loop cycle 68 nested variables 70 pagination feature 70 parameters 69 structure option, control panel 20 T tag attributes about 54 tags, using 55 tag conditionals 56 tag pairs 55 tags about 35 basic tag 54 in templates 56, 57 review 79 tag attributes 54 tag conditionals 56 tag pairs 55 using, in tag attributes 55 theme layouts 53 theme options form building 53 theme partials about 57, 58 adding 80, 81 theme.php file about 50, 77 creating 50, 51 themes about 50 folder structure 49, 76 themes options 51, 52 Typo3 U uninstall() method 43 upgrade() method 43 users option, control panel 21 W website stream data, adding to 82, 83 where parameter using, in stream tags 70 widgets in modules 47 WordPress 5, 35 [ 90 ] www.it-ebooks.info Thank you for buying Website Development with PyroCMS About Packt Publishing Packt, pronounced 'packed', published its first book }Mastering phpMyAdmin for Effective MySQL Management} in April 2004 and subsequently continued to specialize in publishing highly focused books on specific technologies and solutions Our books and publications share the experiences of your fellow IT professionals in adapting and customizing today's systems, applications, and frameworks Our solution based books give you the knowledge and power to customize the software and technologies you're using to get the job done Packt books are more specific and less general than the IT books you have seen in the past Our unique business model allows us to bring you more focused information, giving you more of what you need to know, and less of what you don't Packt is a modern, yet unique publishing company, which focuses on producing quality, cutting-edge books for communities of developers, administrators, and newbies alike For more information, please visit our website: www.packtpub.com About Packt Open Source In 2010, Packt launched two new brands, Packt Open Source and Packt Enterprise, in order to continue its focus on specialization This book is part of the Packt Open Source brand, home to books published on software built around Open Source licences, and offering information to anybody from advanced developers to budding web designers The Open Source brand also runs Packt's Open Source Royalty Scheme, by which Packt gives a royalty to each Open Source project about whose software a book is sold Writing for Packt We welcome all inquiries from people who are interested in authoring Book proposals should be sent to author@packtpub.com If your book idea is still at an early stage and you would like to discuss it first before writing a formal book proposal, contact us; one of our commissioning editors will get in touch with you We're not just looking for published authors; if you have strong technical skills but no writing experience, our experienced editors can help you develop a writing career, or simply get some additional reward for your expertise www.it-ebooks.info Joomla! E-Commerce with VirtueMart ISBN: 978-1-84719-674-3 Paperback: 476 pages Build feature-rich online stores with Joomla! 1.0/1.5 and VirtueMart 1.1.x Build your own e-commerce web site from scratch by adding features step-by-step to an example e-commerce web site Configure the shop, build product catalogues, configure user registration settings for VirtueMart to take orders from around the world Manage customers, orders, and a variety of currencies to provide the best customer service Building Websites with Joomla! 1.5 ISBN:978-1-847195-30-2 Paperback: 384 pages The best-selling Joomla! tutorial guide updated for the final release Learn Joomla! 1.5 features Install and customize Joomla! 1.5 Configure Joomla! administration Create your own Joomla! templates Extend Joomla! with new components, modules, and plug-ins Please check www.PacktPub.com for information on our titles www.it-ebooks.info Joomla! VirtueMart 1.1 Theme and Template Design ISBN: 978-1-849514-54-5 Paperback: 384 pages Give a unique look and feel to your VirtueMart e-commerce store Thorough discussion of template structure, available fields, and customization possibilities More than 50 real-world exercises that can be directly adapted to your store A comprehensive reference to all templates in the VirtueMart default theme including usage of each template and all available fields Integrate with existing Joomla! plugins and JavaScript frameworks Building E-commerce Sites with Drupal Commerce Cookbook ISBN: 978-1-782161-22-6 Paperback: 206 pages Over 50 recipes to help you build engaging, responsive E-commerce sites with Drupal Commerce Learn how to build attractive eCommerce sites with Drupal Commerce Customise your Drupal Commerce store for maximum impact Reviewed by the creators of Drupal Commerce: The CommerceGuys Please check www.PacktPub.com for information on our titles www.it-ebooks.info .. .Website Development with PyroCMS Quickly and efficiently develop and deploy impressive websites with PyroCMS Zachary Vineyard BIRMINGHAM - MUMBAI www.it-ebooks.info Website Development with PyroCMS. .. management, and application development He's been building websites with PHP for the last 10 years He lives in Meridian, Idaho, with his wife and twin girls This book would not exist without the support... layouts Chapter 6, Using PyroCMS Streams, teaches you how to create and use streams of data in PyroCMS using the PyroStreams module Chapter 7, Building a Website with PyroCMS, shows you how to