<< back to overview WebYep - The Shiny Tiny WebCMS
This is one of a series of articles about WebYep and web design. Things are under development right now, so appearance and content may change over time.

Making Meta-Data editable with WebYep

Usually you will use WebYep to make your page's content editable, but sometimes it might be necessary to edit the page's meta data (i.e. title, keywords, etc). Since a browser displays only the contents of the <body> tag, we can't simply put a WebYep ShortText element in our page's <title>.

But we can use the WebYep API to retrieve the content of a WebYep element! All we've got to do is define an element somewhere on the page and display its content somewhere else.

Preparing the page

For this example we will make the page title editable. The first step is easy: create a ShortText element (important: not global!) somewhere on the page:

<?php webyep_shortText("PageTitle", false); ?>

Step 2: output the content of this ShortText element in your <title> tag.

<title><?php echo webyep_sShortTextContent("PageTitle", false); ?></title>

This function returns the content of the specified element (in this case "PageTitle") and the PHP function echo prints it.

From now on the page title is editable. There is only one drawback: the ShortText field is clearly visible on the page.

Hiding the input field in in non-edit mode

Since this is meta data we only want to display the WebYep element in non-edit mode. Normal visitors shall not see it.

To achive this we have to wrap the WebYep field and any HTML we used to distinguish it from regular content in PHP code like this:

<?php if (webyep_bIsEditMode()) { ?>
<?php } ?>

Everything between those 2 code snippets will only be visible in edit mode.

Take a look at the example to see this in action (this will require a server with PHP and WebYep installed).