Jump to content

Developer Documentation

Tagging content with Content Items

Content items can be tagged by members. Tags can be used to find other different types of content with the same tags. A prefix is one of the item's tags which is shown highlighted and prefixes the title when displayed.

 

How to implement tagging

Tagging requires that your content items belong inside a container node. First, you need to implement the tagging interface:

implements \IPS\Content\Tags

Then, you can display the prefix and tags in the view for your item, like so:

{{if $item->prefix()}}
	<a href="{url="app=core&module=system&controller=tags&tag={$item->prefix()}" seoTemplate="tags"}">{$item->prefix()}</a>
{{endif}}

{{if count( $file->tags() )}}
	<ul>
		{{foreach $file->tags() as $tag}}
			<li>
				<a href="{url="app=core&module=system&controller=tags&tag={$tag}" seoTemplate="tags"}">{$tag}</a>
			</li>
		{{endforeach}}
	</ul>
{{endif}}

 

Changes after implementation

  • A field to input tags will be added to the create/edit form.
  • Prefixes and tags will be displayed in content tables.

 

Additional model methods available

boolean static canTag( [ \IPS\Member $member [, \IPS\Node\Model $container ] ] )

Indicates whether the user has permission to tag items.

  • $member (\IPS\Member, optional)
    If provided, will use this member's permissions when checking. By default, the currently-logged in member will be used.
  • $container (\IPS\Node\Model, optional)
    If provided, checks whether the member is able to tag in this specific node.

 

boolean static canPrefix( [ \IPS\Member $member [, \IPS\Node\Model $container ] ] )

Indicates whether the user has permission to select a tag as a prefix on items.

  • $member (\IPS\Member, optional)
    If provided, will use this member's permissions when checking. By default, the currently-logged in member will be used.
  • $container (\IPS\Node\Model, optional)
    If provided, checks whether the member is able to select a prefix on items in this specific node.

 

array tags()

Returns an array of tags on the item.

 

string prefix( [ boolean $encode ] )

Returns the prefix on the item (NULL if the item has no prefix)

  • $encode (boolean, optional, default FALSE)
    If true, will url-encode the returned prefix.

  Report Document


×
×
  • Create New...