GCN JS Library

GCN JS Tags

1 Tag Containers

Several objects in the GCN Library contain Tags. These objects include folders, files, and pages. Each one of these objects surfaces an API with the following additional methods tag(), tags(), createTag(), and removeTag().

1.1 Example


// Render two tags into the DOM
GCN.page(42).tag('title').render('h2.content-header');
GCN.page(42).tag('content').render('#content-div');

1.2 Exmaple


(function () {
	// List the name of all tags in page 42
	GCN.page(42).tags(function (tags) {
		for (var i = 0; i < tags.length; i++) {
			console.log(tags[i].prop('name'));
		}
	});
}());

2 Rendering Tags

There are two ways in which tags can be rendered: via the render() method or the edit(). The difference between these two functions is that edit() will render a tag in such a way that it will be useful for inline editing. If Aloha Editor is available, editable tags which are rendered into the DOM through the edit() method will automatically be initialized into Aloha Editables.

3 Garbage Collection

Any link tags which are no longer used within a tag that was rendered are automatically removed during saving of the rendered tag’s container object.

4 Tag Parts

Tags are constructed out of various “parts”. Each part is of a given type, called a parttype, and holds a value that is appropriate for its type. These values can be simple primitive types like strings, numbers, and booleans; but they can be more complex types like objects containing various properties.

Below is a list of types that a tag can have:

4.1 Parttypes

  • STRING – Plain text string
  • RICHTEXTHTML stings
  • BOOLEANtrue or false
  • PAGE – A number representing a content not page object id, or a string that specifies an external url
  • FILE – A number representing a content not file object id
  • IMAGE – A number representing a content not image object id
  • FOLDER – A number representing a content not folder object id
  • SELECT – An object containing setting of a select menu field.

Unlike tags, it is not possible to create tag parts, since a tag’s parts are determined by the tag’s Tag Type. The GCN Library allows you to read any tag parts, and to write to some tag part.

When updating a tag part, it is important to write a value that is appropriate or else the value may not be saved as you intended.

4.2 Example


	GCN.page(1).tag('link1, function (tag) {
		tag.part('linktext, 'Home Page')
		   .part('url', 'http://www.gentics.com')
		   .parent().save();

		console.log(tag.part('linktext') +
			' links to: ' + tag.part('url'));
	});