Renders methods
The following methods are made to help you render your content. They are all based on a content model object:
\Blackbird\ContentManager\Model\Content
To get a content, you can load it by his ID, or by collection of several contents (see getCollection() section of this page).
Table of content:
- Renders methods
- Get the content object
- Get all raw values
- Get a specific value by his field identifier
- Get content type model
- Get custom fields collection
- Get image URL for an image field type
- Get file absolute URL, for a file field type
- Get the full content url
- Get content collection for content field type
- Render a field in HTML
- Get the content attributes
- Get a content attribute by his code
- Get the current store for a content
- Get all store ids for a content
- Check if the content exists for a given store id
Get the content object
You can retrieve the current content in your template as following : (by using the \Blackbird\ContentManager\Block\View
block)
$content = $block->getContent();
Get all raw values
1 $content->getData();
Get a specific value by his field identifier
$content->getData('field_identifier');
$content->getFieldIdentifier(); $content->getAttributeText('field_identifier'); // Get the option label for a select field type.
Get content type model
$contentType = $content->getContentType();
Get custom fields collection
$customFields = $contentType->getCustomFieldCollection();
Get image URL for an image field type
$content->getImage($fieldIdentifier, $width = null, $height = null, $keepAspectRatio = false, $cropped = false)
- $width: defined the width of the image, if null take the original width of the image
- $height: defined the height of the image, if null take the original height of the image
- $keepAspectRatio: force to keep the aspect ratio of the image
- $croped: force to return the cropped instead of original image if it exists, false by default
Get file absolute URL, for a file field type
$content->getFile($fieldIdentifier);
Get the full content url
$content->getLinkUrl();
If $content is retrieved by a collection, url_key attribute must be selected.
Get content collection for content field type
$content->getContentCollection($fieldIdentifier, $attributes);
- $fieldIdentifier: the string identifier of your field.
- $attributes: PHP array, list of the fields you want to select for further use : ['title', 'url_key', 'news_date']
Render a field in HTML
$content->render($element, $params);
$params: PHP array, extra parameters for your field, will override default ones. Depending on your field type:
- label: string - The label of the element
- label_type: int -
- 0 to hide the label
- 1 for showing the label over the field value
- 2 for label below the field value
- 3 for an inline label
- html_label_tag: string - The html label tag.
- html_tag: string - The html element for the whole wrapper of the field value
- html_id: string - wrapper html id
- html_class: string - wrapper html css classes
- has_link: string -
- 0 for no link
- 1 to wrap the field value with a link to the corresponding content.
- type: string - The output format of your field, accepted values, depending of your field type are:
- Checkbox: checkbox_list_values, checkbox_list_titles, checkbox_comma_values, checkbox_comma_titles
- Radio: radio_select_title, radio_select_value
- Multiple select: multiple_list_values, multiple_list_titles, multiple_comma_values, multiple_comma_titles
- Date: date_short, date_medium, date_long
- Date time: date_time_short, date_time_medium, date_time_long
- Drop down: drop_select_title, drop_select_value
- File: file_filename_without, file_filename_with, file_custom_label
- Image: image_cropped, image_original
- Category: category_name
- Product: product_all, product_name, product_name_image, product_name_image_price, product_name_price
- Content: content_name, content_name_linked, content_list, content_view
- Country: country_name
- Customer: customer_name
- width: int - Image width
- height: int - Image height
- link: int (0 or 1) - Wrap the image by a link pointing to the original image
Get the content attributes
$content->getAttributes();
Get a content attribute by his code
$content->getAttribute('attribute_code');
Get the current store for a content
$content->getStore();
Get all store ids for a content
$content->getStoreIds();
Check if the content exists for a given store id
$content->existsForStore($storeId);