HeadStyle Helper O elemento HTML <style> é usado para incluir folhas de estilo CSS de forma inline no elemento HTML <head>. Use o HeadLink para "linkar" arquivos CSS O HeadLink deve ser usado para criar elementos <link> para a inclusão de folhas de estilo externas. HeadScript é usado quando você deseja definir folhas de estilo inline. O assistente HeadStyle dá suporte aos seguintes métodos para a configuração e adição de declarações de folhas de estilo: appendStyle($content, $attributes = array()) offsetSetStyle($index, $content, $attributes = array()) prependStyle($content, $attributes = array()) setStyle($content, $attributes = array()) Em todos os casos, $content é a verdadeira declaração CSS. $attributes são quaisquer atributos adicionais que você dejesa prover para a tag style: lang, title, media, ou dir são todos admissíveis. HeadStyle também permite a captura de declarações de estilo; isso pode ser útil se você quiser criar as declarações através de programação, e então colocalas em outro lugar. A utilização disso será mostrada em um exemplo abaixo. Finalmente, você pode usar o método headStyle() para acrescentar rapidamente elementos de declaração; a assinatura para isso é headStyle($content$placement = 'APPEND', $attributes = array()). $placement deve ser 'APPEND', 'PREPEND', ou 'SET'. HeadStyle sobrescreve append(), offsetSet(), prepend(), e set() para forçar o uso dos métodos especiais listados acima. Internamente ele armazena cada item como um token stdClass , que depois é serializado usando o método itemToString(). Isso permite que você faça verificações nos itens da pilha, e opcionalmente modifique estes itens simplesmente modificando o objeto retornado. O assistente HeadStyle é uma implementação concreta do assistente Placeholder. Uso Básico do Assistente HeadStyle Você pode especificar uma nova tag de estilo a qualquer momento: headStyle()->appendStyle($styles); ?> ]]> A ordenação é muito importante no CSS; você talvez tenha que assegurar que as declarações sejam carregadas em uma ordem específica devido à ordem do CSS; use as diretivas append, prepend, e offsetSet para lhe auxiliar nessa tarefa: headStyle()->offsetSetStyle(100, $customStyles); // place at end: $this->headStyle()->appendStyle($finalStyles); // place at beginning $this->headStyle()->prependStyle($firstStyles); ?> ]]> When you're finally ready to output all style declarations in your layout script, simply echo the helper: headStyle() ?> ]]> Capturing Style Declarations Using the HeadStyle Helper Sometimes you need to generate CSS style declarations programmatically. While you could use string concatenation, heredocs, and the like, often it's easier just to do so by creating the styles and sprinkling in PHP tags. HeadStyle lets you do just that, capturing it to the stack: headStyle()->captureStart() ?> body { background-color: bgColor ?>; } headStyle()->captureEnd() ?> ]]> The following assumptions are made: The style declarations will be appended to the stack. If you wish for them to replace the stack or be added to the top, you will need to pass 'SET' or 'PREPEND', respectively, as the first argument to captureStart(). If you wish to specify any additional attributes for the <style> tag, pass them in an array as the third argument to captureStart().