The S2 HowTo Journal

Tips, Tricks, and Tutorials for Basic S2 Customization

Previous Entry Share Next Entry
[paidaccount][component] Adding Components
howto_user wrote in s2howto
Paid Accounts Only
The following tutorial requires creating and editing a custom style, which in turn requires a paid, permanent, or early adopter account. Please read What are the paid account benefits? and How do I buy a paid account? to learn about the paid account benefits and how to buy a paid account.

This is an overview of how to further customize Component with additional components or HTML that otherwise couldn't be entered. It will override the function print_free_text(Page p). This new code will be placed in a theme layer. If you already have a theme layer, you will need to edit it and add the code below. If you do not have a theme layer, you will need to create one by following the instructions in the Theme Layer tutorial.

Adding components

NOTE: This code will work only if you have enabled Free Text Component in your settings on the Customize page. If you don't want to have a Free Text Component, do not disable it in your settings. Simply do not enter any text in Free Text box provided in the settings.

To add a component you will need to insert the following code into your theme layer, making sure to copy everything:

function print_free_text(Page p) {
  if ($*free_text_text and $*free_text) {
    print_comp_header($*free_text_text);
    """$*free_text""";
    print_comp_footer();
  }

print_comp_header("Your Component Header"); """The contents of the Component (your text/HTML) goes here."""; print_comp_footer();
}

Change "Your Component Header" to what you wish your new component header to be. Add the contents of your component in the indicated place. Note that the text will not be auto-formatted, so you will need to format it with HTML.

You can add as many components as you wish by repeating the code highlighted in orange.

Displaying components on certain view types

The components will normally appear on all the views of your journal. However, if you would like to have different components depending on the page type or if you simply don't wish to clutter other pages, you can select where it appears. You can choose one of the following view types: recent, friends, archive, month, day, entry, reply. For the explanations of what each view is, please see the overview of S2 View Types.

The following code will add a component to display only on your Recent entries page. Again make sure to copy everything. Replace recent with one of the view types listed above if you wish it to display on a different view type.

function print_free_text(Page p) {
  if ($*free_text_text and $*free_text) {
    print_comp_header($*free_text_text);
    """$*free_text""";
    print_comp_footer();
  }

if ($p.view == "recent") { print_comp_header("Your Component Header"); """The contents of the Component (your text/HTML) goes here."""; print_comp_footer(); }
}

Compile your layer, and it's ready to use. You will need to apply your theme layer via the Customize interface in order for your changes to take effect.

Contributed by </a></b></a>xevinx and </a></b></a>camomiletea.


Comments Disabled:

Comments have been disabled for this post.

?

Log in

No account? Create an account