Commit Graph

168 Commits

Author SHA1 Message Date
Fabien Potencier e1178abfa1 Document storing an enum in a variable to avoid repeating its FQCN 2026-06-03 21:58:29 +02:00
Fabien Potencier 1cde8f2b62 Document template_from_string caveats when used in a sandboxed env 2026-05-20 08:43:49 +02:00
Fabien Potencier f3d5a9f071 Fix typo 2026-03-22 10:08:53 +01:00
Matthias Pigulla 42c12fa720 Add an html_attr function to make outputting HTML attributes easier 2026-03-17 07:39:33 +01:00
Fabien Potencier 77cd2fd9f7 Fix grammar and spelling mistakes in documentation 2026-01-17 22:34:06 +01:00
Hugo Alliaume bcc5ffc301 Enhance enum.rst with dynamic case example 2026-01-14 22:26:11 +01:00
Andreas Erhard 02c5a4b0b6 Add caution note for random function usage 2025-11-04 11:55:35 +01:00
Hugo Alliaume def4abbd5e Improve documentation examples for enum and enum_cases
It may be obvious, but I first thought initializing an BackendEnum with a certain value could be possible with `enum(FQCN, value)`, but it does not, it always returns the first case  instance (if exists).

Instead, `enum(FQCN).from(value)` must be used, I think it's worth to improve `enum()` examples.
2025-09-12 18:14:50 +02:00
Christian Flothmann 057ea92274 replace typographic quote with straigt single quote
make DOCtor-RST 1.68 happy and account for OskarStark/doctor-rst#2011
2025-05-17 21:08:00 +02:00
Fabien Potencier f14f2208f9 Tweaks html_cva docs 2025-03-30 09:51:16 +02:00
Fabien Potencier 7b2fe7cf14 minor #4613 Update html_cva.rst (seb-jean)
This PR was merged into the 3.x branch.

Discussion
----------

Update html_cva.rst

Commits
-------

1a46d12033 Update html_cva.rst
2025-03-30 09:50:03 +02:00
Fabien Potencier 77a6da9cc7 minor #4616 [Docs] Replace = by : in code examples (smnandre)
This PR was merged into the 3.x branch.

Discussion
----------

[Docs] Replace `=` by `:` in code examples

Replace `=` by `:` in code examples
* function/include
* filters/format_number

Commits
-------

84b0499dbd [Docs] Replace `=` by `:` in code examples
2025-03-20 22:33:01 +01:00
Simon André a7c0482dc9 [Doc] Fix code-block in html_cva
There is no `terminal` code-block in the current Twig documentation.

Using `bash` here instead is more in line with the other pages.

(...and will allow to simplify CSS needed for code blocks)
2025-03-20 07:30:17 +01:00
Simon André 84b0499dbd [Docs] Replace = by : in code examples
* function/include
* filters/format_number
2025-03-20 07:23:44 +01:00
seb-jean 1a46d12033 Update html_cva.rst 2025-03-12 18:12:07 +01:00
Jacob Dreesen ccec90c85c Use : instead of = for named argument in the docs 2025-03-06 17:34:44 +01:00
Matthieu Pétel 83da53c3f1 Fix typo for html_cva code example
Fix a typo where 'red' should be 'blue' according to the above code.
2025-01-28 10:51:09 +01:00
Baptiste 3889bc7b18 Fix typo in enum twig doc functions 2025-01-02 09:42:18 +01:00
Javier Eguiluz 84daad9a27 [Doc] Update the docs about attribute() function 2024-12-19 08:39:55 +01:00
Pepperoni1337 03792f643f Use .html.twig file extension in documentation instead of .html 2024-12-18 11:01:27 +01:00
seb-jean 99ea35e1e8 Change = to : for named arguments 2024-12-14 19:49:00 +01:00
Ruud Kamphuis 7556fe1c6f Simplify enum usage in docs 2024-11-21 09:11:11 +01:00
Jacob Dreesen 151b05b2bb Fix some typos in html_cva docs 2024-11-08 19:22:16 +01:00
Fabien Potencier 1d22d300fa Revert "feature #4409 Deprecate the range function (fabpot)"
This reverts commit 99c6fbd517, reversing
changes made to 868b429853.
2024-10-24 15:37:54 +02:00
Fabien Potencier 3d99e595c8 Deprecate the range function 2024-10-24 14:02:46 +02:00
Fabien Potencier 5ac03a440c minor #4376 Move sandbox docs to its own chapter in the docs (fabpot)
This PR was merged into the 3.x branch.

Discussion
----------

Move sandbox docs to its own chapter in the docs

I've also added more information about potential security issues when exposing something that takes a callable as an argument.

Commits
-------

6688a8df16 Move sandbox docs to its own chapter in the docs
2024-10-04 21:01:30 +02:00
Fabien Potencier 6688a8df16 Move sandbox docs to its own chapter in the docs 2024-10-04 21:00:19 +02:00
seb-jean 86b23eba23 Update html_cva.rst 2024-10-04 07:32:20 +02:00
nicolas-joubert f16382ba91 [Doc] Fix enum title
Copy/Paste fix from enum_case documentation page
2024-09-30 23:05:34 +02:00
Fabien Potencier 1d31ac4b77 Tweak previous merge 2024-09-28 09:57:08 +02:00
Fabien Potencier 8efdab4780 minor #3983 Added details in the doc of filters and functions of IntlExtension (FlorianChenot)
This PR was squashed before being merged into the 3.x branch.

Discussion
----------

Added details in the doc of filters and functions of IntlExtension

Commits
-------

8716392603 Added details in the doc of filters and functions of IntlExtension
2024-09-28 09:46:54 +02:00
unknown 8716392603 Added details in the doc of filters and functions of IntlExtension 2024-09-28 09:46:50 +02:00
Nicolas Grekas cff6f1ca80 Implement the enum function 2024-09-27 08:23:21 +02:00
Fabien Potencier 048183eaa6 Add cross-link 2024-09-13 14:06:34 +02:00
Fabien Potencier 8d1af0fc03 Let's no deprecate the attribute function yet 2024-09-13 13:56:05 +02:00
Fabien Potencier 333638e8e6 Allow to use a dynamic attribute on the . operator via () 2024-09-12 21:44:45 +02:00
Fabien Potencier 08f28fd06c Remove most usage of foo/bar/baz in the docs 2024-09-12 21:40:08 +02:00
Fabien Potencier b1c35cd1fc Tweak docs 2024-09-12 19:19:56 +02:00
Fabien Potencier a39b6e164c minor #4241 Adjust cycle implementation (smnandre)
This PR was squashed before being merged into the 3.x branch.

Discussion
----------

Adjust `cycle` implementation

Update code following [#4158](https://github.com/twigphp/Twig/issues/4158)
* return mixed
* trigger when non countable
* type the position argument

Add doc precisions

Commits
-------

7c3c1615 Adjust `cycle` implementation
2024-08-30 20:43:09 +02:00
Simon André 7c3c16154e Adjust cycle implementation 2024-08-30 20:43:06 +02:00
Ruud Kamphuis 8c3df0c0bc Clarify block function
It actually renders the block again.
2024-08-28 08:20:39 +02:00
Fabien Potencier 1d5a8dc98b Fix html_cva docs 2024-08-18 09:38:48 +02:00
Fabien Potencier e85519fcd9 Fix html_cva docs 2024-08-18 09:38:02 +02:00
Fabien Potencier 0bfef5b300 feature #4006 Introduce CVA to html-extra (WebMamba)
This PR was squashed before being merged into the 3.x branch.

Discussion
----------

Introduce CVA to html-extra

Hey! This PR introduces CVA to Twig. All of this has already been merged into SymfonyUX (https://github.com/symfony/ux/pull/1416), but `@kbond` suggested that this repo can be a better place for this feature.

Here is a description from the PR merged in to SymfonyUX:

------------------------------

This PR introduces a new concept CVA (Class Variance Authority), by adding a1 twig function, to help you manage your class in your component.

Let's take an example an Alert component. In your app, an alert can have a lot of different styles one for success, one for alert, one for warning, and different sizes, with icons or not... You need something that lets you completely change the style of your component without creating a new component, and without creating too much complexity in your template.

Here is the reason came CVA.

Your Alert component can now look like this:

```twig
{% props color = 'blue', size = 'md' %}

{% set alert =  html_cva(
      'alert rounded-lg',
     {
        color: {
            blue: 'text-blue-800 bg-blue-50 dark:bg-gray-800 dark:text-blue-400',
            red: 'text-red-800 bg-red-50 dark:bg-gray-800 dark:text-red-400',
            green: 'text-green-800 bg-green-50 dark:bg-gray-800 dark:text-green-400',
            yellow: 'text-yellow-800 bg-yellow-50 dark:bg-gray-800 dark:text-yellow-400',
        },
        size: {
            sm: 'px-4 py-3 text-sm',
            md: 'px-6 py-4 text-base',
            lg: 'px-8 py-5 text-lg',
        }
    },
    [{
           color: ['red'],
           size: ['lg'],
          class: 'font-semibold'
    }],
   {
           rounded: 'md'
    }
}) %}

<div class="{{ cva.apply({color, size}, attribute.render('class'), 'flex p-4') }}">
    ...
</div>
```

So here you have a `cva` function that lets you define different variants of your component.

You can now use your component like this:
```twig
<twig:Alert color="red" size="md"/>

<twig:Alert color="green" size="sm"/>

<twig:Alert color="yellow" size="lg"/>

<twig:Alert color="red" size="md" class="dark:bg-gray-800"/>
```

And then you get the following result:

<img width="1269" alt="Capture d’écran 2024-01-24 à 00 52 33" src="https://github.com/symfony/ux/assets/32077734/6a5e25be-5b81-4ae7-8385-0fa5422d0396">

If you want to know more about the concept I implement here you can look at:
- CVA (js version): https://cva.style/docs
- tailwind merge: https://github.com/gehrisandro/tailwind-merge-php, https://github.com/dcastil/tailwind-merge
- this implementation by using tailwind-merge and cva is inspired a lot by: https://ui.shadcn.com/ (shadcn is the most starred library on github in 2023)
- a really good article that explains the philosophy behind https://manupa.dev/blog/anatomy-of-shadcn-ui
- this PR works great in a LASTstack: https://symfonycasts.com/screencast/last-stack/last-stack

Tell me what you think about it! Thanks for your time! Cheers 🧡

------------

Commits
-------

e3ac14e1 Introduce CVA to html-extra
2024-08-18 09:36:20 +02:00
Matheo Daninos e3ac14e1c8 Introduce CVA to html-extra 2024-08-18 09:36:16 +02:00
Fabien Potencier 0c30e78b1c Add support for named arguments on special functions 2024-08-16 08:37:24 +02:00
Christophe Coevoet ff4d01f940 Implement the enum_cases function
The implementation contains an optimized implementation of the function
for the common case of using a string literal as the argument. It will
validate the enum existence during compilation and compile the code to
use `MyEnum::cases()` directly.
2024-08-09 21:21:58 +02:00
Fabien Potencier c44be99a84 Rename array to sequence 2024-06-22 19:37:51 +02:00
Fabien Potencier 8f8d67b489 Add some missing functions in docs 2022-12-27 13:34:33 +01:00
seb-jean b376bdd0a9 Add function twig *_name for intl list 2022-12-27 12:49:56 +01:00