PixyBlog Lightbox   |   Basket   |   Login   |   Register
Pixy® Blog - Expose Yourself
  PixyBlog.comPhotoblog DiscussionPhotoblog Wiki
  • Log in / create account
Using models, objects and macros
  • Page
  • Discussion
  • View source
  • History

Using models, objects and macros

From PixyWiki

Jump to: navigation, search

pixyBlog makes website data available to page templates in the form of models and data objects and makes it easy for you to generate the HTML for your website by providing macros. Let's explain these new terms.

  • Model objects: Model objects provide access to data from pixyBlog and specifically from your website. A model object returns data objects or collections or data objects. In Model Object Reference, we'll describe each model, it's properties and methods.
  • Data objects: Data objects each represent an item of data within your website, for example there is a Website object that represents your website, Entry objects which represent individual website entries and Bookmark objects that represent items in your blogroll. In Data Object Reference, we'll describe each data object, it's properties and methods.
  • Macros: A macro is Velocity routine that generates HTML based on a data object or a collection of data objects. In Macro Reference we'll describe each of pixyBlog's built-in macros.

Let's discuss how to access data via models and data objects.

Contents

  • 1 Accessing data via models and objects
    • 1.1 Accessing object properties
    • 1.2 Calling object methods
  • 2 Calling macros

Accessing data via models and objects

Models and data objects are objects and there are two ways to access data from objects. One way is to access an objects properties. Another is to call the object's methods. Let's talk about these two techniques.

Accessing object properties

To access an objects properties, you use a simple dot-notation. For example, if you want to display the pixyBlog version number property of the $config model object, you do something like this in your page:

<p>$config.pixyVersion</p>

Or, if you'd like to save the pixyBlog version number in a variable named $version, you'd do this:

#set( $version = $config.pixyVersion )

And some properties are themselves objects, which in turn have their own properties and methods. For example, you can get the Website object from the $model object and from the Website object you can display the websites name and description like so:

<p>$model.weblog.name</a>
<p>$model.weblog.description</a>

Calling object methods

Another way to access an object's data is to call an object's methods. Methods are different from properties because they require parameters. You use the same simple dot-notation, but you must end the expression with a list of parameters in parentheses. For example, if you'd like to display an image from within your theme, you can use the $url model like so:

<img='$url.themeResource("basic", "background.gif")'></a>

Argument one is the name of the theme and argument two is the name of a file that exists in the theme's directory. Note that a comma is used to separate the arguments.

Calling macros

In page templates, you get data from objects and you use template code to display that data as HTML. To help you along, pixyBlog includes some macros which can be used to generate commonly used HTML constructs on your website. There are macros for displaying your website entries, displaying your blogroll and displaying a comment form.

Calling a macro is a little different from calling an object. A macro call starts with a # pound-sign, followed by the macro name and the macro parameters enclosed in parentheses. For example, you call the website calendar macro like so:

#showWeblogEntryCalendar($model.weblog "nil")

Argument one is the website for the calendar and argument two is the gallery, where "nil" indicates that no gallery is specified. Note that the arguments for a macro are separated by a space and NOT a comma as was the case for methods.

Retrieved from "http://wiki.pixyblog.com/Using_models%2C_objects_and_macros"
This page was last modified 14:30, 26 August 2009. This page has been accessed 882 times.
  • Privacy policy
  • About PixyWiki
  • Disclaimers
  • Powered by MediaWiki
  • Design by Paul Gu
Terms and Conditions | Privacy Policy | About | Contact us | Copyright © 2006-2008 Pixy® Ltd. All rights reserved.