|
| 1 | +# Symfony Code Snippets And Twig Support |
| 2 | + |
| 3 | +Over 50 Symfony Code Snippets for PhP code And Over 50 Twig Code Snippets. |
| 4 | +Just type the letters 'sy' to get a list of all available Symfony Code Snippets. |
| 5 | +For Twig Just Type the Tag name and you will get AutoCompletion. |
| 6 | + |
| 7 | +## For using the snippets in the Annotations Comments you need to add this Code To Your Settings.json File |
| 8 | + |
| 9 | +```json |
| 10 | + "editor.quickSuggestions": { |
| 11 | + "other": true, |
| 12 | + "comments": true, |
| 13 | + "strings": true |
| 14 | + } |
| 15 | +``` |
| 16 | + |
| 17 | +### You Can Use It In The Annotations Comments |
| 18 | + |
| 19 | + |
| 20 | + |
| 21 | +### You Can Use It In The PHP Code |
| 22 | + |
| 23 | + |
| 24 | + |
| 25 | +### You Can Use It In Twig Files ♥ |
| 26 | + |
| 27 | + |
| 28 | + |
| 29 | +## Snippets Symfony |
| 30 | + |
| 31 | +Trigger | Description |
| 32 | +--- | --- |
| 33 | +syControllerFunction | use this snippets to generate function in the controller with Route,RouteName,FunctionName,Template for rendering in twig. |
| 34 | +syFormGen | use this snippet to generate $form variable into the controller function change the formtype and the entity. |
| 35 | +syHandleRequest | use this snippet to Generate handleRequest Function change the RequestVar with your requestvar name. |
| 36 | +syRemove | use this snippet to remove or delete data from the database do not forgot to inject the class entitymanagerenterface in the function parametters |
| 37 | +syRedirectToRoute | use this snippet to generate return to redirecttoroute name change the routeName with Your RouteName. |
| 38 | +syRedirect | use this snippet to return the redirection to url |
| 39 | +syUserHash | use this function to generate function for hashing the users password don not forgot to setup the file security.yaml. |
| 40 | +syTwigForm | use this function to send the $form var to the frontend using twig. |
| 41 | +syLogout | use this snippet to generate logout function withe symfony you just need to setup the file security.yaml. |
| 42 | +syAddFlash | use this snippet to generate flash message you need to setup the display code in the file base.html.twig. |
| 43 | +syTwigVar | use this snippet to send the vars to twig via the function render. |
| 44 | +syRender | use this snippet to generate render function to send the view into twig. |
| 45 | +syGetUser | use this snippet to get the current conected user. |
| 46 | +syDump | use this snippet to generate the dump function in symfony. |
| 47 | +syJson | use this snippet to generate return json in symfony controller. |
| 48 | +syFindAll | use this snippet to generate the function findAll from one repository you need to inject the repo you want in the function parameters. |
| 49 | +syFindOneBy | use this snippet to generate the function findOneBy to get one value from repo do not forgot to inject the repository in this function parameters. |
| 50 | +syFindOne | use this snippet to generate the function findOne you need to inject the repo in this function parameters. |
| 51 | +syFindBy | use this function to generate the function findBy from one repo do not forgot to incject the repo you want in this function parameters. |
| 52 | +syManager | use this snippet to generate the var $manager to reacte with the database. |
| 53 | +syRepo | use this snippet to generate the $repo var ex $repo = $this->getDoctrine()->getRepository(Product::class);. |
| 54 | +syPersist | use this snippet to generate $manager persist. |
| 55 | +syGetSalt | use this snippet to generate the function getSalt for the user entity when you implaments the UserInterFace. |
| 56 | +syGetUsername | use this snippet to generate the function getUsername for the user entity when you implaments the UserInterFace. |
| 57 | +syEraseCredentials | use this snippet to generate the function eraseCredentials for the user entity when you implaments the UserInterFace. |
| 58 | +syQueryBuilder | use this snippt to create querybuilder in the repos to get data from the database. |
| 59 | +syEqualTo | use this snippet to generate the assert equalto in the symfony Annotations. |
| 60 | +syLength | use this snippet to generate the assert Length in the symfony Annotations. |
| 61 | +syNotBlank | use this snippet to generate the assert NotBlank in the symfony Annotations. |
| 62 | +syEmail | use this snippet to generate the assert Email in the symfony Annotations. |
| 63 | +syUrl | use this snippet to generate the assert Url in the symfony Annotations. |
| 64 | +syNotEqualTo | use this snippet to generate the assert notequalto in the symfony Annotations. |
| 65 | +syGreaterThan | use this snippet to generate the assert GreaterThan in the symfony Annotations. |
| 66 | +syUniqueEntity | use this snippent to generate uniqueEntity to make sure that the fields are uniques. |
| 67 | +syhasLife | use this snippet to generate the Annotation @ORM\\HasLifecycleCallbacks() in symfony entity. |
| 68 | +syPre | use this snippet to generate the * @ORM\\PrePersist * @ORM\\PreUpdate . |
| 69 | + |
| 70 | +### Snippets Twig |
| 71 | + |
| 72 | +Trigger | Twig Code | Type |
| 73 | +---|---|--- |
| 74 | +attribute | `{{ attribute() }}` | Function |
| 75 | +autoescape | `{% autoescape %}{% endautoescape %}` | Tag |
| 76 | +block | `{% block name %}{% endblock %}` | Tag |
| 77 | +batch | `batch(size, fill)` | Filter |
| 78 | +constant | `{{ constant('constName') }}` | Test |
| 79 | +convert_encoding | `convert_encoding('to', 'from')` | Filter |
| 80 | +cycle | `{{ cycle(array, position) }}` | Filter |
| 81 | +date | `date("m/d/Y")` | Filter |
| 82 | +datef | `{% set currentDate = date() %}` | Function |
| 83 | +date_modify | `date_modify("+1 day")` | Function |
| 84 | +default | `default('defaultValue')` | Function |
| 85 | +dump | `<pre>{{ dump(array) }}</pre>` | Function |
| 86 | +do | `{% do someOp %}` | Tag |
| 87 | +encoreCss | `{{ encore_entry_link_tags('app') }}` | Function |
| 88 | +encoreJs | `{{ encore_entry_scropt_tags('app') }}` | Function |
| 89 | +else | `{% else %}` | Tag |
| 90 | +else if | `{% elseif condition %}` | Tag |
| 91 | +embed | `{% embed "fileName.html.twig" %}{% endembed %}` | Tag |
| 92 | +execute | `{% %}` | NULL |
| 93 | +extends |`{% extends "fileName.html.twig" %}`| Tag |
| 94 | +filter |`{% filter filterName %}{% endfilter %}` | Tag |
| 95 | +flush | `{% flush %}` | Tag |
| 96 | +for | `{% for row in array %}{% endfor %}` | Tag |
| 97 | +for else | `{% for row in array %}{% else %}{% endfor %}` | Tag |
| 98 | +for if else | `{% for row in array if condition %}{% else %}{% endfor %}` | Tag |
| 99 | +format | format() | Filter |
| 100 | +formTwig | `{{form_start(form)}}{{form_widget(form)}}{{form_end(form)}}` | Function |
| 101 | +if | `{% if condition %}{% endif %}` | Tag |
| 102 | +if else | `{% if condition %}{% else %}{% endif %}` | Tag |
| 103 | +import | `{% import "fileName.html.twig" as alias %}` | Tag |
| 104 | +include | `{% include "fileName.html.twig" %}` | Tag |
| 105 | +join | `join('separator')` | Filter |
| 106 | +json_encode | `json_encode()` | Filter |
| 107 | +loop | `loop.` | Filter With AutoComplation |
| 108 | +macro | `{% macro name() %}{% endmacro %}` | Tag |
| 109 | +max | `{% set result = max(array) %}` | Filter |
| 110 | +merge | `merge(array)` | Filter |
| 111 | +min | `{% set result = min(array) %}` | Filter |
| 112 | +number_format | `number_format(1, '${.}', '${,}')` | Filter |
| 113 | +parent | `{{ parent() }}` | Function |
| 114 | +random | `{% set result = random() %}` | Function |
| 115 | +range | `range(low, high, step)` | Function |
| 116 | +range set | `{% set result = range(low, high, step) %}` | Function |
| 117 | +replace | `replace('search' : 'replace')` | Filter |
| 118 | +round | `round(, 'floor')` | Filter |
| 119 | +sandbox | `{% sandbox %}{% endsandbox %}` | Tag |
| 120 | +set | `{% set varName = value %}` | Tag |
| 121 | +show | `{{ }}` | Null |
| 122 | +slice | `slice(start, length)` | Filter |
| 123 | +source | `{{ source('fileName.html.twig') }}` | Tag |
| 124 | +spaceless | `{% spaceless %}{% endspaceless %}` Tag |
| 125 | +split | `split('')` | Filter |
| 126 | +self | `_self` | Null |
| 127 | +template | `{{ include(template_from_string("strings")) }}` | Function |
| 128 | +trim | `trim('')` | Filter |
| 129 | +use | `{% use "fileName.html.twig" %}` | Tag |
| 130 | +verbatim | `{% verbatim %}{% endverbatim %}` Tag |
| 131 | + |
| 132 | +## Source |
| 133 | + |
| 134 | +[Github](https://github.com/nalabdou/Symfony-code-snippets) |
0 commit comments