HtmlHelper

Type
Class
Namespace
Craft
Inherits
Craft\HtmlHelper » CHtml
Since
1.0

Class HtmlHelper

See also http://craftcms.com

View source

Public Properties

PropertyDescription
$afterRequiredLabelstring – The HTML code to be appended to the required label.
$beforeRequiredLabelstring – The HTML code to be prepended to the required label.
$closeSingleTagsboolean – Whether to close single tags.
$countinteger – The counter for generating automatic input field names.
$errorContainerTagstring – The tag name for the error container tag.
$errorCssstring – The CSS class for highlighting error inputs.
$errorMessageCssstring – The CSS class for displaying error messages (see {@link error}).
$errorSummaryCssstring – The CSS class for displaying error summaries (see {@link errorSummary}).
$liveEvents– Sets the default style for attaching jQuery event handlers.
$renderSpecialAttributesValueboolean – Whether to render special attributes value.
$requiredCssstring – The CSS class for required labels.

Public Methods

MethodDescription
activeCheckBox()Generates a check box for a model attribute.
activeCheckBoxList()Generates a check box list for a model attribute.
activeColorField()Generates a color picker field input for a model attribute.
activeDateField()Generates a date field input for a model attribute.
activeDateTimeField()Generates a datetime field input for a model attribute.
activeDateTimeLocalField()Generates a datetime-local field input for a model attribute.
activeDropDownList()Generates a drop down list for a model attribute.
activeEmailField()Generates an email field input for a model attribute.
activeFileField()Generates a file input for a model attribute.
activeHiddenField()Generates a hidden input for a model attribute.
activeId()Generates input field ID for a model attribute.
activeLabel()Generates a label tag for a model attribute.
activeLabelEx()Generates a label tag for a model attribute.
activeListBox()Generates a list box for a model attribute.
activeName()Generates input field name for a model attribute.
activeNumberField()Generates a number field input for a model attribute.
activePasswordField()Generates a password field input for a model attribute.
activeRadioButton()Generates a radio button for a model attribute.
activeRadioButtonList()Generates a radio button list for a model attribute.
activeRangeField()Generates a range field input for a model attribute.
activeSearchField()Generates a search field input for a model attribute.
activeTelField()Generates a telephone field input for a model attribute.
activeTextArea()Generates a text area input for a model attribute.
activeTextField()Generates a text field input for a model attribute.
activeTimeField()Generates a time field input for a model attribute.
activeUrlField()Generates a url field input for a model attribute.
activeWeekField()Generates a week field input for a model attribute.
ajax()Generates the JavaScript that initiates an AJAX request.
ajaxButton()Generates a push button that can initiate AJAX requests.
ajaxLink()Generates a link that can initiate AJAX requests.
ajaxSubmitButton()Generates a push button that can submit the current form in POST method.
asset()Generates the URL for the published assets.
beginForm()Generates an opening form tag.
button()Generates a button.
cdata()Encloses the given string within a CDATA tag.
checkBox()Generates a check box.
checkBoxList()Generates a check box list.
closeTag()Generates a close HTML element.
colorField()Generates a color picker field input.
css()Encloses the given CSS content with a CSS tag.
cssFile()Links to the specified CSS file.
dateField()Generates a date field input.
dateTimeField()Generates a datetime field input.
dateTimeLocalField()Generates a local datetime field input.
decode()Decodes special HTML entities back to the corresponding characters.
dropDownList()Generates a drop down list.
emailField()Generates an email field input.
encode()Encodes special characters into HTML entities.
encodeArray()Encodes special characters in an array of strings into HTML entities.
encodeParams()Will take an HTML string and an associative array of key=>value pairs, HTML encode the values and swap them back into the original string using the keys as tokens.
endForm()Generates a closing form tag.
error()Displays the first validation error for a model attribute.
errorSummary()Displays a summary of validation errors for one or several models.
fileField()Generates a file input.
form()Generates an opening form tag.
getIdByName()Generates a valid HTML ID based on name.
hiddenField()Generates a hidden input.
htmlButton()Generates a button using HTML button tag.
image()Generates an image tag.
imageButton()Generates an image submit button.
label()Generates a label tag.
link()Generates a hyperlink tag.
linkButton()Generates a link submit button.
linkTag()Generates a link tag that can be inserted in the head section of HTML page.
listBox()Generates a list box.
listData()Generates the data suitable for list-based HTML elements.
listOptions()Generates the list options.
mailto()Generates a mailto link.
metaTag()Generates a meta tag that can be inserted in the head section of HTML page.
modelName()Generates HTML name for given model.
normalizeUrl()Normalizes the input parameter to be a valid URL.
numberField()Generates a number field input.
openTag()Generates an open HTML element.
pageStateField()Generates a hidden field for storing persistent page states.
passwordField()Generates a password field input.
radioButton()Generates a radio button.
radioButtonList()Generates a radio button list.
rangeField()Generates a range field input.
refresh()Registers a 'refresh' meta tag.
renderAttributes()Renders the HTML tag attributes.
resetButton()Generates a reset button.
resolveName()Generates input name for a model attribute.
resolveNameID()Generates input name and ID for a model attribute.
resolveValue()Evaluates the attribute value of the model.
script()Encloses the given JavaScript within a script tag.
scriptFile()Includes a JavaScript file.
searchField()Generates a search field input.
setModelNameConverter()Set generator used in the {@link CHtml::modelName()} method. You can use the null value to restore default generator.
statefulForm()Generates a stateful form tag.
submitButton()Generates a submit button.
tag()Generates an HTML element.
telField()Generates a telephone field input.
textArea()Generates a text area input.
textField()Generates a text field input.
timeField()Generates a time field input.
urlField()Generates a URL field input.
value()Evaluates the value of the specified attribute for the given model.
weekField()Generates a week field input.

encodeParams()

Will take an HTML string and an associative array of key=>value pairs, HTML encode the values and swap them back into the original string using the keys as tokens.

View source

Arguments

  • $html (string) – The HTML string.
  • $variables (array) – An associative array of key => value pairs to be applied to the HTML string using strtr.

Returns

string – The HTML string with the encoded variable values swapped in.

Signature

public static string encodeParams ( $html, $variables = [] )

Protected Methods

MethodDescription
activeInputField()Generates an input HTML tag for a model attribute.
addErrorCss()Appends {@link errorCss} to the 'class' attribute.
clientChange()Generates the JavaScript with the specified client changes.
inputField()Generates an input HTML tag.

Constants

ConstantDescription
ID_PREFIX