PHPackages                             bubnov/twig-markers - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Templating &amp; Views](/categories/templating)
4. /
5. bubnov/twig-markers

ActiveGit[Templating &amp; Views](/categories/templating)

bubnov/twig-markers
===================

php Twig extention filter allows you replace placeholders in text by content context

1.0.0(9y ago)014MITPHPPHP &gt;=5.3.3

Since Jan 23Pushed 9y ago1 watchersCompare

[ Source](https://github.com/bubnov-mikhail/twig-markers)[ Packagist](https://packagist.org/packages/bubnov/twig-markers)[ Docs](https://github.com/bubnov-mikhail/twig-markers)[ RSS](/packages/bubnov-twig-markers/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (1)Versions (2)Used By (0)

twig-markers
============

[](#twig-markers)

Description
===========

[](#description)

```
Twig extention filter allows you replace placeholders
in text by context of the content.
You MUST extend base class, implement "findContext" method
and may add as many "onMarker***"
(where *** is name of placeholder) as you want.
In twig template you should pass Entity object
as a context of the text with placeholders.
In "onMarker***" method you may check or/and request
require context from provided one.
In "findContext" method you must check if provided context
is a requested one or may try find it from provided (see example)

```

Installation
============

[](#installation)

```
Add require to your composer.json:

```

```
"bubnov/twig-markers": "master"
```

```
Edit app/config/services.yml:

```

```
twig.markers:
        class: Path to your extended class
        tags:
            - { name: twig.extension }
```

Usage examples
==============

[](#usage-examples)

```
Lets say we have App\ProjectBundle\Entity\Project.
It has some App\ReportBundle\Entity\Report (s).
Each of Reports has some App\ReportBundle\Entity\Widget (s).

If you provide App\ReportBundle\Entity\Widget as a context, this Entity
should have methods to find it's parent Report, and/or it's parent Project.
Lets Project has "site" property and you want
to insert Projects's site url into Widgets's text.
Widgets's text is:

```

\#Widget's text:

```
This is widget text for project %link%. Click it!

```

\#Twig:

```
{{ widget.text | markers(widget) | raw}}
```

\#PHP:

```
protected function onMarkerLink()
{
	if($context = $this->findContext('App\ProjectBundle\Entity\Project'))
	{
	    return $context->getLink();
	}

	return false;
}

protected function findContext($findContext)
{
        $contextClass = get_class($this->context);
        if($contextClass === $findContext)
        {
            return $this->context;
        }

	//Try to find requested context from provided
	switch($contextClass)
	{
            case 'App\ReportBundle\Entity\Widget':
                switch($findContext)
                {
                    case 'App\ReportBundle\Entity\Report':
                        return $this->context->getReport();
                        break;
                    case 'App\ProjectBundle\Entity\Project':
                        return $this->context->getReport()->getProject();
                        break;
                }
                break;
            case 'App\ReportBundle\Entity\Report':
                switch($findContext)
                {
                    case 'App\ProjectBundle\Entity\Project':
                        return $this->context->getProject();
                        break;
                }
                break;
	}
        return false;
}
```

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

3393d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/cfc35f6ef7f8c1025f89bed8181c928aac39c2fb9884009f8b9dc44fc50c7020?d=identicon)[bubnov](/maintainers/bubnov)

---

Top Contributors

[![bubnov-mikhail](https://avatars.githubusercontent.com/u/5926697?v=4)](https://github.com/bubnov-mikhail "bubnov-mikhail (2 commits)")

---

Tags

twig-extensionsymfonytwigplaceholdertwig-extension

### Embed Badge

![Health badge](/badges/bubnov-twig-markers/health.svg)

```
[![Health](https://phpackages.com/badges/bubnov-twig-markers/health.svg)](https://phpackages.com/packages/bubnov-twig-markers)
```

###  Alternatives

[dms/twig-extension-bundle

DMS Twig Extension Bundle, leverages Fabien Potencier's extra twig extensions for your website.

19296.3k](/packages/dms-twig-extension-bundle)[boekkooi/jquery-validation-bundle

Jquery form validation bundle for symfony 2

2773.9k1](/packages/boekkooi-jquery-validation-bundle)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
