Download the PHP package namelesscoder/fluid-parameters without Composer

On this page you can find all versions of the php package namelesscoder/fluid-parameters. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package fluid-parameters

Latest Stable Version Total Downloads Monthly Downloads Coverage Status

TYPO3 Fluid extension fluid_parameters

API to enable declaring parameters for a Fluid template, partial, layout or section within any of those types of files.

What does it do?

In short: allows you to declare required and optional parameters for a Fluid asset. It does this by emulating a subset of the features that would have been part of Fluid 3.0, namely f:parameter. On top of this it adds a couple of tricks for convenience.

Installation

To install, simply do composer req namelesscoder/fluid-parameters. That's it - no configuration is necessary. If you use the package in a TYPO3 CMS installation this automatically adds f:parameter, f:description and f:parameter.mode as ViewHelpers. If you are not within a TYPO3 CMS installation you nave to manually add the namespace {namespace f=\NamelessCoder\FluidParameters\ViewHelpers} in templates where you want to use the feature.

Feature set:

Together, these features allow a developer who writes Fluid template files to ensure that necessary variables are present when the template file is rendered and that optional variables can have a default value. And they allow an integrator who renders the templates to be informed if a necessary variable is not present or does not have a compatible data type - without having detailed knowledge of every template file's content.

How to use:

No configuration is required - simply use the f:parameter ViewHelper in your Fluid template and the rest happens automatically. The f:parameter ViewHelper can be used in any Layout, Template or Partial, and within sections defined in any of those types of files. Declared parameters are specific to the file or section - as soon as you render another file or section, only the parameters of that other file or section will be considered.

Adding a required parameter

This throws an error if {title} is not assigned as template variable when rendering the template.

Optional parameter

This does not throw an error if {title} is not assigned. Instead, it automatically assigns the variable with a value of Default title.

Supported parameter types

Furthermore, custom class names are supported and can be specified by FQN or short name. If specified by short name, any object instance of a class with that short name will be allowed - and no type casting will be done. If specified by FQN, only instances of the class or subclasses thereof will be allowed - and type casting will be possible by taking non-object values and passing them as single constructor argument for the class using new $className($value).

Every type, including custom objects, also supports an "array-of-types" by adding [] to the type, e.g. string[]. This can even be done to multiple levels, e.g. string[][] to require "an array of arrays of strings".

Specific required value

This causes an error to be thrown if assigning variable {color} is not one of the exact values red, green or blue - and selects red as the default value.

Undeclared variables

Sets the parameter handling mode to strict which means that if this template is rendered with an undeclared variable, an error is thrown:

Results in an error:

By default, undeclared variables are allowed. By setting the mode to strict this behavior is changed.

Note that f:parameter.mode must be used BEFORE any occurrences of f:parameter to have an effect.

Usage within sections

Has the exact same effect as declaring the parameter on a template, partial or layout - but only applies when rendering the section. If the section is rendered with an undeclared variable assigned, an error is thrown (due to mode=strict). If {text} is not assigned when rendering the section, it is automatically assigned with a value of Default text.

Describing a template

Output:

Essentially, any content you use within f:description is not rendered as output when the template/section is rendered. Note: do not use any Fluid code within the description block! If you do, the description text will be truncated and only includes any text leading up to the first Fluid code. Invalid Fluid code within this block will still cause a template parsing error!

Extracting "Reflections" of parameters/descriptions

The package contains an API to extract information about which parameters apply to a given template, along with the contents of the f:description block within the template. This can be used to build your own style guide or reference.

Consider the following example template file located at /path/to/my/template.html:

Using the extraction API is fairly straight-forward:

The $reflection variable now contains an instance of TemplateReflection which holds properties describing the template. You can use this reflection instance to extract all metadata:

It is further possible to extract the same type of reference for each of the f:section nodes within the template file. Each of the values returned from $reflection->getSections() is an instance of SectionReflection:

Together this would produce an output like this:

The $reflection instance can of course also be assigned to a Fluid template to render the reference. Use Fluid's standard iteration and variable access to achieve the exact output you want, e.g. {reflection.description}, <f:for each="{reflection.parameterDefinitions}" as="definition">...</f:for> and so on - just like you would normally iterate arrays and output variables.

Differences between this extension and fluid_components

You may or may not already be aware of an extension "Fluid Components" created by sitegeist - these two extensions are somewhat similar in that they allow Fluid templates to define required variables, but they are very different in their implementation philosophy.

These two extensions can coexist peacefully and can be mixed to some extent (sections rendered by Fluid Components can be fitted with parameters declared by Fluid Parameters); however, parameters declared with one are not known to the other. It is therefore a fully viable use case to use Fluid Components for some contexts and Fluid Parameters for others, in the same project.

The following table shows the differences:

Fluid Parameters Fluid Components
Supports declaring parameters for templates
Supports default values for parameters/variables
Supports validation of parameters' data type
Supports reference / parameter documentation
Zero-config
High performance / light-weight
Works for any template
Works for individual sections
Can be rendered as native FLUIDTEMPLATE TS object
Compatible with Flux templates
Works for Fluid outside of TYPO3 CMS *
Requires special syntax to define rendering
Supports custom data type casting
Works by overriding internal Fluid classes
Makes template files emulate a ViewHelper
Requires custom Fluid namespaces
Allows XSD integration for auto-completion
Has a "living styleguide" implementation

(* If you manually register the namespace with {namespace f=\NamelessCoder\FluidParameters\ViewHelpers})

In essence: use Fluid Parameters if you...

And use Fluid Components if you...

Credits

This work was kindly sponsored by Busy Noggin.


All versions of fluid-parameters with dependencies

PHP Build Version
Package Version
Requires typo3fluid/fluid Version ^2
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package namelesscoder/fluid-parameters contains the following files

Loading the files please wait ....