Create a token

When you try to add or modify a token, you'll find this view:

Token name

It's the text that will be replaced, ie MY_TOKEN.

[Note]Note

Please entry it on uppercase, alphabetics only, without any spaces or digits. Avoid colons (:), since it's reserved char, used to parse data from tokens (you'll learn more when we'll add a date token).

Integration

It's the "domain" of integration; at the moment there is Joomla! and Virtuemart; in the future more will come (K2, JEvents and so on).

Token type

It's the type of the token, it could be:

  • Date

  • Google+

  • Link

  • Meta

  • Plain text

They are almost the same, but you have to "style" it in template overrides in a different way.

Published

To publish/unpublish a token

Token replace

This is the most important field, since it holds Schema.org attributes. If you know what to add, you can add them manually; in the other case you can explore the type/attributes tree and then click on Add type or Add attribute button.

[Note]Note

Please note that J4Schema can't verify if the data you added is correct, since you could add nested tokens. To ensure that everything is ok, you can use this Google tool: Rich Snippets Testing Tool

However in our pro-version you can find a module named J4Schema Rich Tools tester. It will submit the current url to the Google tool, you only have to publish it wherever you want and follow the link.

Now you know everything you need to start adding tokens, let's start with an example.

Add tokens

Ok, let's say we want to add some information to the article we have just created in the previous examples (the one about the "Avatar" film, do you remember?).

Here you can find the sections of the article view that we can style:

  1. Article title

  2. Category

  3. Publish date (or any other date such as Creation date or Modified date)

  4. Related links

So this is a snippet of a template override for the article (some parts were removed):

[Note]Note

In these examples there is a space between the token name and { or }. We had to do so to prevent Joomla to parse them as plugin in these articles; inside template overrides you have to remove that space.

Example 5.1. Article Tokens

<div { ARTICLE_WRAPPER } class="item-page<?php echo $this->pageclass_sfx?>">
[...]
	<div { ARTICLE_BODY }>
    [...]
<?php if ($params->get('show_title')) : ?>
	<h2 { ARTICLE_TITLE }>
	<?php if ($params->get('link_titles') && !empty($this->item->readmore_link)) : ?>
		<a { ARTICLE_LINK } href ="<?php echo $this->item->readmore_link; ?>">
		<?php echo $this->escape($this->item->title); ?></a>
	<?php else : ?>
		<?php echo $this->escape($this->item->title); ?>
	<?php endif; ?>
	</h2>
<?php endif; ?>

[...]

<?php if ($params->get('show_category')) : ?>
	<dd class="category-name" { ARTICLE_CATEGORY }>
	[...]
	</dd>
<?php endif; ?>
      [...]
	</div>
</div>

        

If you use our tokens, too, this is the HTML output:

Example 5.2. Article HTML after token replace

<div class="item-page" itemtype="http://schema.org/WebPage" itemscope>
[...]
    <div itemprop="mainContentOfPage">
    [...]
        <h2 itemprop="name">
          <a href ="" itemprop="url">J4Schema</a>
        </h2>
    [...]
        <dd itemprop="genre" class="category-name">
            Category: <a href ="test-blog">Blog</a>
        </dd>
    [...]	
    </div>
</div>

          


This is only a simple example, but, as you can see, once you set up everything, it works automatically! Even in the worst case (token not replaced) your page style won't be affected, since your browser will ignore the tokens!

[Tip]Can I add a token wherever I want?

The short answer is: Yes, you can!.

Here it is the longer and more techincal one. J4Schema uses a system plugin, loaded in the onAfterRender event. This event is fired just before sending the output, so we can manipulate the text however we want!

Now let's see a particular token: the date token