S2 Cookbook: Properties

From Dreamwidth Notes
Jump to: navigation, search

Setting a property

Note: this can NOT be done inside of a function. Most layers set any properties before they write functions, although this is not necessary.

# set all of the interaction links for users, entries, and comments
# to be text instead of icons
set userlite_interaction_links = "text";
set entry_management_links = "text";
set comment_management_links = "text";

Accessing a property

Let's say that you want to access a property. The property has already been set in the current layer or a higher layer:

# sets the page background color property
set color_page_background = "#FFF";

You can then access the property by putting a * between the property name and the variable access symbol $.

# prints #ffffff 
# even though we set it to #FFF because it is a color object
# and not a string
print $*color_page_background;

Creating a new property

Before creating a new property, you might want to make sure and check an existing core2 property doesn't already exist for the purpose you want.

Putting a property into the customization wizard

Useful system properties

# Examples of system properties when used on Dreamwidth.org

# Name of the current Dreamwidth site
# Dreamwidth Studios
print $*SITENAME + "\n";
# Shorter name of the current Dreamwidth site.
# Dreamwidth
print $*SITENAMESHORT + "\n";
# Abbreviation of the current Dreamwidth site.
# DW
print $*SITENAMEABBREV + "\n";
# The base URL of the current Dreamwidth site,
# without a trailing slash.
# http://www.dreamwidth.org
print $*SITEROOT + "\n";
# The base URL of the current Dreamwidth site's image directory,
# without a trailing slas
# http://s.dreamwidth.org/img
print $*IMGDIR + "\n";
# The base URL of palimg files, without a trailing slash.
# http://www.dreamwidth.org/palimg
print $*PALIMGROOT + "\n";
# The base URL of the current Dreamwidth site's static files directory, 
# without a trailing slash.
# http://s.dreamwidth.org/stc
print $*STATDIR + "\n";