View Helpers
styleSheetLinkTag()
Signature
Section titled “Signature”styleSheetLinkTag() — returns string
Available in: controller
Category: Asset Functions
Description
Section titled “Description”Returns a link tag for a stylesheet (or several) based on the supplied arguments.
Parameters
Section titled “Parameters”| Name | Type | Required | Default | Description |
|---|---|---|---|---|
sources | string | no | — | The name of one or many CSS files in the stylesheets folder, minus the .css extension. Pass a full URL to generate a tag for an external style sheet. Can also be called with the source argument. |
type | string | no | text/css | The type attribute for the link tag. |
media | string | no | all | The media attribute for the link tag. |
rel | string | no | — | The rel attribute for the relation between the tag and href. |
head | boolean | no | false | Set to true to place the output in the head area of the HTML page instead of the default behavior (which is to place the output where the function is called from). |
delim | string | no | , | The delimiter to use for the list of CSS files. |
encode | boolean | no | true | Use this argument to decide whether the output of the function should be encoded in order to prevent Cross Site Scripting (XSS) attacks. Set it to true to encode all relevant output for the specific HTML element in question (e.g. tag content, attribute values, and URLs). For HTML elements that have both tag content and attribute values you can set this argument to attributes to only encode attribute values and not tag content. |
Examples
Section titled “Examples”// 1. Include a single stylesheet from the `stylesheets` folder
// Generates: <link rel="stylesheet" href="/stylesheets/app.css" ...>
writeOutput(styleSheetLinkTag("app"));
// 2. Include multiple stylesheets with a comma-delimited list
// Generates two separate <link> tags for blog.css and comments.css
writeOutput(styleSheetLinkTag("blog,comments"));
// 3. Include a stylesheet for print media only
writeOutput(styleSheetLinkTag(sources="print", media="print"));
// 4. Include an external stylesheet via full URL
writeOutput(styleSheetLinkTag("https://fonts.googleapis.com/css2?family=Roboto"));
// 5. Push a stylesheet into the <head> from anywhere in the view
// The tag is injected into the <head> section rather than rendered inline
writeOutput(styleSheetLinkTag(sources="tabs", head=true));
// 6. Use a pipe delimiter instead of the default comma
writeOutput(styleSheetLinkTag(sources="reset|layout|theme", delim="|"));