symfony API

AssetHelper Functions

You are currently browsing
the website for symfony 1

Visit the Symfony2 website


« Back to API menu

1.2 API OpenSearch

Packages

You are currently browsing the symfony API for the 1.2 version. Switch to:
This version of symfony is not maintained anymore.
If some of your projects still use this version, consider upgrading as soon as possible.

AssetHelper.

Function Summary

  • string auto_discovery_link_tag($type = 'rss', $url = '', $tag_options = array())
    Returns a <link> tag that browsers and news readers can use to auto-detect a RSS or ATOM feed for the current page, to be included in the <head> section of a HTML document.
  • decorate_with($layout)
    Decorates the current template with a given layout.
  • string dynamic_javascript_include_tag($uri, $absolute = false, $options = array())
    Returns a <script> include tag for the given internal URI.
  • string get_javascripts()
    Returns <script> tags for all javascripts configured in view.yml or added to the response object.
  • string get_javascripts_for_form($form)
    Returns <script> tags for all javascripts associated with the given form.
  • string get_stylesheets()
    Returns <link> tags for all stylesheets configured in view.yml or added to the response object.
  • string get_stylesheets_for_form($form)
    Returns <link> tags for all stylesheets associated with the given form.
  • string image_path($source, $absolute = false)
    Returns the path to an image asset.
  • string image_tag($source, $options = array())
    Returns an <img> image tag for the asset given as argument.
  • string include_http_metas()
    Returns a set of <meta http-equiv> tags according to the response attributes, to be included in the <head> section of a HTML document.
  • include_javascripts()
    Prints <script> tags for all javascripts configured in view.yml or added to the response object.
  • include_javascripts_for_form($form)
    Prints <script> tags for all javascripts associated with the given form.
  • string include_metas()
    Prints a set of <meta> tags according to the response attributes, to be included in the <head> section of a HTML document.
  • include_stylesheets()
    Prints <link> tags for all stylesheets configured in view.yml or added to the response object.
  • include_stylesheets_for_form($form)
    Prints <link> tags for all stylesheets associated with the given form.
  • string include_title()
    Returns the title of the current page according to the response attributes, to be included in the <title> section of a HTML document.
  • string javascript_include_tag(0, 1)
    Returns a <script> include tag per source given as argument.
  • string javascript_path($source, $absolute = false)
    Returns the path to a JavaScript asset.
  • string stylesheet_path($source, $absolute = false)
    Returns the path to a stylesheet asset.
  • string stylesheet_tag(0, 1)
    Returns a css <link> tag per source given as argument, to be included in the <head> section of a HTML document.
  • use_dynamic_javascript($js, $position = '', $options = array())
    Adds a dynamic javascript to the response object.
  • use_dynamic_stylesheet($css, $position = '', $options = array())
    Adds a dynamic stylesheet to the response object.
  • use_javascript($js, $position = '', $options = array())
    Adds a javascript to the response object.
  • use_stylesheet($css, $position = '', $options = array())
    Adds a stylesheet to the response object.
  • _compute_public_path($source, $dir, $ext, $absolute = false)
  • _dynamic_path($uri, $format, $absolute = false)

Function Details

  • (string) auto_discovery_link_tag ($type = 'rss', $url = '', $tag_options = array()) Browse code

    $type feed type ('rss', 'atom')
    $url 'module/action' or '@rule' of the feed
    $tag_options additional HTML compliant <link> tag parameters

    Returns a &lt;link&gt; tag that browsers and news readers can use to auto-detect a RSS or ATOM feed for the current page, to be included in the &lt;head&gt; section of a HTML document.


    Options:


    • rel - defaults to 'alternate'

    • type - defaults to 'application/rss+xml'

    • title - defaults to the feed type in upper case



    Examples:
      echo auto_discovery_link_tag('rss', 'module/feed');
    
    => <link rel=\"alternate\" type=\"application/rss+xml\" title=\"RSS\" href=\"http://www.curenthost.com/module/feed\" />
    echo auto_discovery_link_tag('rss', 'module/feed', array('title' => 'My RSS'));
    => <link rel=\"alternate\" type=\"application/rss+xml\" title=\"My RSS\" href=\"http://www.curenthost.com/module/feed\" />

    returns XHTML compliant <link> tag

  • decorate_with ($layout) Browse code

    $layout The layout name or path or false to disable the layout

    Decorates the current template with a given layout.

  • (string) dynamic_javascript_include_tag ($uri, $absolute = false, $options = array()) Browse code

    $uri The internal URI for the dynamic javascript
    $absolute Whether to generate an absolute URL
    $options An array of options

    Returns a &lt;script&gt; include tag for the given internal URI.


    The helper automatically adds the sf_format to the internal URI, so you don't have to.

    returns XHTML compliant <script> tag(s)

  • (string) get_javascripts () Browse code

    Returns &lt;script&gt; tags for all javascripts configured in view.yml or added to the response object.


    You can use this helper to decide the location of javascripts in pages. By default, if you don't call this helper, symfony will automatically include javascripts before </head>. Calling this helper disables this behavior.

    returns <script> tags

  • (string) get_javascripts_for_form ($form) Browse code

    $form

    Returns &lt;script&gt; tags for all javascripts associated with the given form.


    The scripts are set by implementing the getJavaScripts() method in the corresponding widget.

     class MyWidget extends sfWidgetForm
    
    {
    public function getJavaScripts()
    {
    return array('/path/to/a/file.js');
    }
    }

    returns <script> tags

  • (string) get_stylesheets () Browse code

    Returns &lt;link&gt; tags for all stylesheets configured in view.yml or added to the response object.


    You can use this helper to decide the location of stylesheets in pages. By default, if you don't call this helper, symfony will automatically include stylesheets before </head>. Calling this helper disables this behavior.

    returns <link> tags

  • (string) get_stylesheets_for_form ($form) Browse code

    $form

    Returns &lt;link&gt; tags for all stylesheets associated with the given form.


    The stylesheets are set by implementing the getStyleSheets() method in the corresponding widget.

     class MyWidget extends sfWidgetForm
    
    {
    public function getStyleSheets()
    {
    return array('/path/to/a/file.css');
    }
    }

    returns <link> tags

  • (string) image_path ($source, $absolute = false) Browse code

    $source asset name
    $absolute return absolute path ?

    Returns the path to an image asset.


    Example:

      echo image_path('foobar');
    
    => /images/foobar.png

    Note: The asset name can be supplied as a...


    • full path, like "/my_images/image.gif"

    • file name, like "rss.gif", that gets expanded to "/images/rss.gif"

    • file name without extension, like "logo", that gets expanded to "/images/logo.png"



    returns file path to the image file

  • (string) image_tag ($source, $options = array()) Browse code

    $source image asset name
    $options additional HTML compliant <img> tag parameters

    Returns an &lt;img&gt; image tag for the asset given as argument.


    Options:


    • 'absolute' - to output absolute file paths, useful for embedded images in emails

    • 'alt' - defaults to the file name part of the asset (capitalized and without the extension)

    • 'size' - Supplied as "XxY", so "30x45" becomes width="30" and height="45"



    Examples:
      echo image_tag('foobar');
    
    => <img src=\"images/foobar.png\" alt=\"Foobar\" />
    echo image_tag('/my_images/image.gif', array('alt' => 'Alternative text', 'size' => '100x200'));
    => <img src=\"/my_images/image.gif\" alt=\"Alternative text\" width=\"100\" height=\"200\" />

    returns XHTML compliant <img> tag

  • (string) include_http_metas () Browse code

    Returns a set of &lt;meta http-equiv&gt; tags according to the response attributes, to be included in the &lt;head&gt; section of a HTML document.


    Examples:

      include_http_metas();
    
    => <meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\" />

    Note: Modify the view.yml or use sfWebResponse::addHttpMeta() to change, add or remove HTTP metas.

    returns XHTML compliant <meta> tag(s)

  • include_javascripts () Browse code

    Prints &lt;script&gt; tags for all javascripts configured in view.yml or added to the response object.

  • include_javascripts_for_form ($form) Browse code

    $form

    Prints &lt;script&gt; tags for all javascripts associated with the given form.

  • (string) include_metas () Browse code

    Prints a set of &lt;meta&gt; tags according to the response attributes, to be included in the &lt;head&gt; section of a HTML document.


    Examples:

      include_metas();
    
    => <meta name=\"title\" content=\"symfony - open-source PHP5 web framework\" />
    <meta name=\"robots\" content=\"index, follow\" />
    <meta name=\"description\" content=\"symfony - open-source PHP5 web framework\" />
    <meta name=\"keywords\" content=\"symfony, project, framework, php, php5, open-source, mit, symphony\" />
    <meta name=\"language\" content=\"en\" /><link href=\"/stylesheets/style.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />

    Note: Modify the view.yml or use sfWebResponse::addMeta() to change, add or remove metas.

    returns XHTML compliant <meta> tag(s)

  • include_stylesheets () Browse code

    Prints &lt;link&gt; tags for all stylesheets configured in view.yml or added to the response object.

  • include_stylesheets_for_form ($form) Browse code

    $form

    Prints &lt;link&gt; tags for all stylesheets associated with the given form.

  • (string) include_title () Browse code

    Returns the title of the current page according to the response attributes, to be included in the &lt;title&gt; section of a HTML document.


    Note: Modify the sfResponse object or the view.yml to modify the title of a page.

    returns page title

  • (string) javascript_include_tag (0, 1) Browse code

    0 asset names
    1 additional HTML compliant <link> tag parameters

    Returns a &lt;script&gt; include tag per source given as argument.


    Examples:

      echo javascript_include_tag('xmlhr');
    
    => <script language=\"JavaScript\" type=\"text/javascript\" src=\"/js/xmlhr.js\"></script>
    echo javascript_include_tag('common.javascript', '/elsewhere/cools');
    => <script language=\"JavaScript\" type=\"text/javascript\" src=\"/js/common.javascript\"></script>
    <script language=\"JavaScript\" type=\"text/javascript\" src=\"/elsewhere/cools.js\"></script>

    returns XHTML compliant <script> tag(s)

  • (string) javascript_path ($source, $absolute = false) Browse code

    $source asset name
    $absolute return absolute path ?

    Returns the path to a JavaScript asset.


    Example:

      echo javascript_path('myscript');
    
    => /js/myscript.js

    Note: The asset name can be supplied as a...


    • full path, like "/my_js/myscript.css"

    • file name, like "myscript.js", that gets expanded to "/js/myscript.js"

    • file name without extension, like "myscript", that gets expanded to "/js/myscript.js"



    returns file path to the JavaScript file

  • (string) stylesheet_path ($source, $absolute = false) Browse code

    $source asset name
    $absolute return absolute path ?

    Returns the path to a stylesheet asset.


    Example:

      echo stylesheet_path('style');
    
    => /css/style.css

    Note: The asset name can be supplied as a...


    • full path, like "/my_css/style.css"

    • file name, like "style.css", that gets expanded to "/css/style.css"

    • file name without extension, like "style", that gets expanded to "/css/style.css"



    returns file path to the stylesheet file

  • (string) stylesheet_tag (0, 1) Browse code

    0 asset names
    1 additional HTML compliant <link> tag parameters

    Returns a css &lt;link&gt; tag per source given as argument, to be included in the &lt;head&gt; section of a HTML document.


    Options:


    • rel - defaults to 'stylesheet'

    • type - defaults to 'text/css'

    • media - defaults to 'screen'



    Examples:
      echo stylesheet_tag('style');
    
    => <link href=\"/stylesheets/style.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />
    echo stylesheet_tag('style', array('media' => 'all'));
    => <link href=\"/stylesheets/style.css\" media=\"all\" rel=\"stylesheet\" type=\"text/css\" />
    echo stylesheet_tag('style', array('raw_name' => true));
    => <link href=\"style\" media=\"all\" rel=\"stylesheet\" type=\"text/css\" />
    echo stylesheet_tag('random.styles', '/css/stylish');
    => <link href=\"/stylesheets/random.styles\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />
    <link href=\"/css/stylish.css\" media=\"screen\" rel=\"stylesheet\" type=\"text/css\" />

    returns XHTML compliant <link> tag(s)

  • use_dynamic_javascript ($js, $position = '', $options = array()) Browse code

    $js
    $position
    $options

    Adds a dynamic javascript to the response object.


    The first argument is an internal URI. The helper automatically adds the sf_format to the internal URI, so you don't have to.

  • use_dynamic_stylesheet ($css, $position = '', $options = array()) Browse code

    $css
    $position
    $options

    Adds a dynamic stylesheet to the response object.


    The first argument is an internal URI. The helper automatically adds the sf_format to the internal URI, so you don't have to.

  • use_javascript ($js, $position = '', $options = array()) Browse code

    $js
    $position
    $options

    Adds a javascript to the response object.

  • use_stylesheet ($css, $position = '', $options = array()) Browse code

    $css
    $position
    $options

    Adds a stylesheet to the response object.

  • _compute_public_path ($source, $dir, $ext, $absolute = false) Browse code

    $source
    $dir
    $ext
    $absolute

  • _dynamic_path ($uri, $format, $absolute = false) Browse code

    $uri
    $format
    $absolute