IntelliJ Latte Pro

Getting Started

Provides support for Latte, the best template engine for PHP.

Useful links

Migration guide from free plugin

  • Do not forget to uninstall old free plugin before installing the Pro version
  • XML file was renamed fromlatte-intellij.xml to intellij-latte-pro.xml
  • In XML:
    • Attribute allowedFilters in <tags> was renamed to allowFilters
    • Attribute insertColons in <filters> was removed and replaced by <filterArguments> element
  • Filters, variables and functions cannot be longer configured in IDE preferences. The only way to configure them is via XML
  • Tags configured in XML now require their type (PAIR, UNPAIRED etc.) to be configured in IDE preferences. That can be done via quick fix in XML or via balloon notification when you open project.
  • {label ...} tag cannot be used as unpaired without /} at the end. Use {label ... /} if you want it unpaired.
  • Translation tag {_...} can be used only as unpaired

Installing the Plugin

Installation of IntelliJ Latte Pro is done through IntelliJ IDEA's integrated plugin manager. From within the application, open Preferences and select Plugins from the list on the left-hand side. This will show you the list of currently installed plugins. If you are currently using Latte free plugin then you must uninstall it before installing Latte Pro.

feature-completion

Next, click the Marketplace tab above the list. That allows you to browse through the plugins available on JetBrains' Marketplace. Enter "Latte" into the search field in the top left corner and select Latte Pro from the list. Finally, click the green Install button and restart the application. The plugin should now be installed, and you can set up your project.

feature-completion

Features

  • Everything from the open-source plugin but much faster
  • No problems with big projects
  • Code completion for PHP, classic HTML, attribute tags and more
  • Registering custom tags, filters and custom functions
  • Completion and references for included templates (files)
  • Completion and type check for method/function parameter
  • Support for types defined with <>, eg: array<int, string>

TODO: add some images of features

XML configuration

XML configuration files for Latte plugin are files that contain information about tags, filters, variables etc.

  • Plugin loads all files named intellij-latte-pro.xml in your project including vendor folder or some other folders except ignored folders.
  • You can use more intellij-latte-pro.xml files. All will be loaded, but must have different value in vendor attribute.
  • Tip: distribute intellij-latte-pro.xml files with your Composer package

This is example file content with sample values:

  • Replace myVendor/myPackage to your unique vendor name
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE latte PUBLIC "-//LATTE//Latte plugin XML V0.0.1//EN" ".idea/intellij-latte-pro/xmlSources/Latte.dtd">
<latte vendor="myVendor/myPackage" version="1">
	<tags>
		<tag name="default" type="UNPAIRED">
			<arguments>
				<argument name="variable" types="VARIABLE_DEFINITION_EXPRESSION" required="true" repeatable="true" />
			</arguments>
		</tag>
		<tag name="for" type="PAIR" arguments="initialization; condition; afterthought" multiLine="true" />
	</tags>
	<filters>
		<filter name="npsPrint" description="Print NPS value" />
		<filter name="percentPrint" description="Print percent value (can use null for print -)">
			<filterArguments>
				<filterArgument name="allData" type="float"/>
			</filterArguments>
		</filter>
	</filters>
	<functions>
		<function name="clamp" returnType="int|float" documentation="clamps value">
			<functionArguments>
				<functionArgument name="value" type="int|float"/>
				<functionArgument name="min" type="int|float"/>
				<functionArgument name="max" type="int|float"/>
			</functionArguments>
		</function>
		<function name="odd" returnType="bool" documentation="checks if the given number is odd">
			<functionArguments>
				<functionArgument name="value" type="int"/>
			</functionArguments>
		</function>
	</functions>
	<variables>
		<variable name="control" type="\Nette\Application\UI\Control" />
		<variable name="basePath" type="string" />
		<variable name="baseUrl" type="string" />
		<variable name="flashes" type="mixed[]" />
	</variables>
</latte>

Allowed XML tags and attributes

If a required parameter is missing or invalid item will be skipped.

<tag> in <tags>

attribute required default possible values Description
name yes none any string Name of tag
type yes none PAIR, UNPAIRED, UNPAIRED_ATTR or ATTR_ONLY Type of tag
arguments no "" any string Used after code completion as help
allowFilters no false true, false Used for inspections and completions
multiLine no false true, false Used after code completion
deprecatedMessage no "" any string Message for deprecated tag
description no "" any string Description will be shown in completion dialog
documentation no "" any string Documentation will be shown when you hover over tag element
documentationUrl no "" URL Documentation URL will be shown when you hover over tag element

Attribute type details:

  • PAIR - means pair tag like {form}{/form}
  • UNPAIRED - means unpaired tag like {varType}
  • UNPAIRED_ATTR - means tag used only as unpaired tag like {varType} or n:attribute, like n:else
  • ATTR_ONLY - means tag used only as n:attribute, like n:class

Attribute arguments details:

  • Attribute arguments can contain string which will be shown as help after code completion
  • If attribute arguments is not provided, it means "tag without arguments"
  • Instead of using attribute arguments you can define arguments as child <argument> elements of <arguments> element which is child of <tag>
  • When you use argument settings via <argument> tags, help for code completion will be generated automatically
  • But you can still use argument arguments. When using <argument> tags, then this value will rewrite automatically generated help after code completion

<argument> in <arguments> in <tag>

attribute required default possible values Description
name yes none any string Name of tag argument
types yes none Types are listed under this table Argument types separated by comma
type no mixed PHP type definition Expected return type of argument
required no false true, false Used for inspections and completions
repeatable no false true, false Used for inspections and completions

Attribute types detail:

  • PHP_IDENTIFIER - matches with foo, bar, foo_123, ...
  • PHP_EXPRESSION - matches with $var, foo(), \Bar::, ... (-> | :: property|method|constant)
  • PHP_CONDITION - matches with PHP_EXPRESSION (only use condition as name for completion)
  • PHP_CLASS_NAME - matches with class names \Foo, \Foo\Bar, ...
  • VARIABLE - matches with $var
  • VARIABLE_DEFINITION - matches with $var and mark it as definition
  • VARIABLE_DEFINITION_EXPRESSION - matches with [type] $variable = expr, and mark variable as definition
  • VARIABLE_DEFINITION_ITEM - matches with [type] $var and mark variable as definition
  • BLOCK - matches with #block
  • BLOCK_USAGE - matches with PHP_IDENTIFIER (only use block as name for completion)
  • NONE - matches with string none
  • PHP_TYPE - matches with php type like string, string|null, \Foo\Bar, ...
  • CONTENT_TYPE - matches with content type like application/json, ...
  • LINK_DESTINATION - matches with default, Foo:detail, handleFoo!, ...
  • LINK_PARAMETERS - matches with PHP_EXPRESSION or KEY_VALUE
  • KEY_VALUE - matches with , [var =>] value
  • CONTROL - matches with VARIABLE (only use $control as name for completion)

<filter> in <filters>

attribute required default possible values Description
name yes none any string Name of filter
description no "" any string Used as description for code completion
documentation no "" any string Documentation will be shown when you hover over filter element
documentationUrl no "" URL Documentation URL will be shown when you hover over filter element

<filterArgument> in <filterArguments> in <filter>

attribute required default possible values Description
name yes none any string Name of filter argument
type yes none PHP type definition Type of filter argument
defaultValue no "" any string Default value of argument. No default value means required argument.
description no "" any string Used as description for code completion

<variable> in <variables>

attribute required default possible values Description
name yes none any string Name of PHP variable (without $)
type yes mixed PHP type definition PHP type definition (eg. string)

<function> in <functions>

attribute required default possible values Description
name yes none any string Name of custom function
returnType yes mixed PHP type definition Return type (eg. string)
documentation no "" any string Documentation will be shown when you hover over function element
documentationUrl no "" URL Documentation URL will be shown when you hover over function element

<functionArgument> in <functionArguments> in <function>

attribute required default possible values Description
name yes none any string Name of function argument
type yes none PHP type definition Type of function argument
defaultValue no "" any string Default value of argument. No default value means required argument.
description no "" any string Used as description for code completion

Compatibility

Since 1.0.0, IntelliJ Latte Pro plugin is compatible with IntelliJ IDEA Ultimate and PhpStorm with version 2021.3 and higher.

Bug Reports

Bug reports can be posted in GitHub public repository.

© 2022 Matouš Němec