Difference between revisions of "S2 Cookbook: Properties"

From Dreamwidth Notes
Jump to: navigation, search
(Created page with '== Accessing a property == == Setting a property == == Creating a new property == == Putting a property into the customization wizard == Category: S2 Cookbook')
 
m (Useful system properties: -- expand and comment)
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
 +
== 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.
 +
 +
<syntaxhighlight lang="s2">
 +
# 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";
 +
</syntaxhighlight>
 +
 
== Accessing a property ==
 
== Accessing a property ==
  
== Setting 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:
 +
 
 +
<syntaxhighlight lang="s2">
 +
# sets the page background color property
 +
set color_page_background = "#FFF";</syntaxhighlight>
 +
 
 +
You can then access the property by putting a <code>*</code> between the property name and the variable access symbol <code>$</code>.
 +
 
 +
<syntaxhighlight lang="s2"># prints #ffffff
 +
# even though we set it to #FFF because it is a color object
 +
# and not a string
 +
print $*color_page_background;</syntaxhighlight>
  
 
== Creating a new property ==
 
== Creating a new property ==
 +
 +
Before creating a new property, you might want to make sure and check an [http://www.dreamwidth.org/customize/advanced/layerbrowse?id=core2#table_layerbrowse_properties existing core2 property] doesn't already exist for the purpose you want. 
  
 
== Putting a property into the customization wizard ==
 
== Putting a property into the customization wizard ==
  
 +
== Useful system properties ==
 +
 +
<syntaxhighlight lang="s2">
 +
"""<pre>""";
 +
# 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";
 +
 +
"""</pre>""";
 +
</syntaxhighlight>
  
 
[[Category: S2 Cookbook]]
 
[[Category: S2 Cookbook]]

Latest revision as of 05:31, 25 June 2011

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

"""<pre>""";
# 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";
 
"""</pre>""";