Conn2Flow
Docs navigation

Reference / Libraries

modelo.php library

Variable replacement and delimited-block handling in HTML templates — the foundation of every screen the Gestor renders.

Path in the Gestor bibliotecas/modelo.php

modelo.php is the Gestor's template library. Everything Conn2Flow renders on the server goes through it: pages, layouts, components and widget responses are HTML strings where code replaces markers with values and cuts, repeats or removes blocks. There is no template engine, AST or automatic escaping — only plain string functions.

The library is loaded during the Gestor bootstrap and registers its version in $_GESTOR['biblioteca-modelo'] (currently 1.1.0).

The two kinds of marker

Marker Format Used for
Variable Any literal string, by convention #name# or @[[group#name]]@ A single value
Block ("cell") A pair of comments <!-- name < --> … <!-- name > --> A fragment to extract, repeat, replace or remove

The functions enforce no format: they look for exactly the string they receive. The block comment convention is followed by core modules and widgets.

Replacing variables

Function Occurrences Case
modelo_var_troca($modelo, $var, $valor) first only sensitive
modelo_var_troca_fim($modelo, $var, $valor) last only insensitive
modelo_var_troca_tudo($modelo, $var, $valor) all insensitive
modelo_var_in($modelo, $var, $valor) inserts before the first one, keeping the variable sensitive

When the variable is not found, the template comes back unchanged; there is no error or warning.

modelo_var_troca() and modelo_var_troca_tudo() also accept an associative array instead of $var. Each key is used literally as the marker; no # is added, despite what the function's docblock says:

$html = modelo_var_troca_tudo($html, [
    '#titulo#' => $titulo,
    '#url#'    => $url,
]);

modelo_var_troca_tudo() uses str_ireplace() on purpose. The old preg_replace() version treated $19 inside the value as a group reference and corrupted prices such as $19.97.

Working with blocks

Function Result
modelo_tag_val($modelo, $in, $out) Returns the content between the tags (or '')
modelo_tag_in($modelo, $in, $out, $valor) Replaces the whole block, tags included, with $valor
modelo_tag_troca_val($modelo, $in, $out, $valor) Replaces only the content, keeping the tags
modelo_tag_del($modelo, $in, $out) Removes the whole block, tags included

The repetition ("cell") pattern

This is how core modules build lists on the server: extract the block as a template, leave a marker in its place, and insert each row before the marker.

$cel_nome = 'linha';
// 1. Keep the template and leave a marker where the block was.
$cel = modelo_tag_val($_GESTOR['pagina'], '<!-- '.$cel_nome.' < -->', '<!-- '.$cel_nome.' > -->');
$_GESTOR['pagina'] = modelo_tag_in($_GESTOR['pagina'], '<!-- '.$cel_nome.' < -->', '<!-- '.$cel_nome.' > -->', '<!-- '.$cel_nome.' -->');
// 2. For each record, fill a copy and insert it before the marker (order is preserved).
foreach ($registros as $r) {
    $linha = modelo_var_troca_tudo($cel, '#nome#', htmlspecialchars($r['nome']));
    $_GESTOR['pagina'] = modelo_var_in($_GESTOR['pagina'], '<!-- '.$cel_nome.' -->', $linha);
}
// 3. Remove the marker.
$_GESTOR['pagina'] = modelo_var_troca($_GESTOR['pagina'], '<!-- '.$cel_nome.' -->', '');

The same pair of functions handles conditional blocks: modelo_tag_del() drops the section when the condition is false — for example, the publisher module does this with its templates-todos-linkados-msg messages.

Legacy functions

  • modelo_abrir($modelo_local) reads a file and removes the development block <!--!#del#(#!--> … <!--!#del#)#!-->. It has no callers in the core: templates live in the database and in resources/, not in files read at runtime. It also removes only the first block.

  • modelo_input_in($modelo, $in, $out, $valor) calls paginaTrocaVarValor(), which does not exist in the core. Calling it is a fatal error. It has no callers; do not use it.

See also

Functions

Generated from gestor/bibliotecas/modelo.php · 10 functions

10 of 10

modelo_input_in

view source · line 33 ↗
modelo_input_in(string $modelo, string $name_input_in, string $name_input_out, string $valor): string

Substitui variáveis de input em um modelo HTML.

Parameters

$modelostring
O template HTML onde as substituições serão feitas.
$name_input_instring
Nome do placeholder de entrada (ex: 'campo').
$name_input_outstring
Nome do campo de saída que substituirá o placeholder.
$valorstring
Valor a ser atribuído ao campo.

Returns

string
Retorna o modelo com as variáveis substituídas.

modelo_var_troca

view source · line 57 ↗
modelo_var_troca(string $modelo, string|array $var, string $valor = null): string

Substitui a primeira ocorrência de uma variável em um modelo.

Parameters

$modelostring
O template onde a substituição será feita.
$varstring|array
A variável/placeholder a ser substituída, ou array de variáveis.
$valorstring
O valor que substituirá a variável (ignorado se $var for array).

Returns

string
Retorna o modelo com a primeira ocorrência da variável substituída.

modelo_var_troca_fim

view source · line 101 ↗
modelo_var_troca_fim(string $modelo, string $var, string $valor): string

Substitui a última ocorrência de uma variável em um modelo.

Parameters

$modelostring
O template onde a substituição será feita.
$varstring
A variável/placeholder a ser substituída.
$valorstring
O valor que substituirá a variável.

Returns

string
Retorna o modelo com a última ocorrência da variável substituída.

modelo_var_troca_tudo

view source · line 137 ↗
modelo_var_troca_tudo(string $modelo, string|array $var, string $valor = null): string

Substitui todas as ocorrências de uma variável em um modelo.

Parameters

$modelostring
O template onde as substituições serão feitas.
$varstring|array
A variável/placeholder a ser substituída, ou array de variáveis.
$valorstring
O valor que substituirá todas as ocorrências da variável (ignorado se $var for array).

Returns

string
Retorna o modelo com todas as ocorrências da variável substituídas.

modelo_var_in

view source · line 165 ↗
modelo_var_in(string $modelo, string $var, string $valor): string

Insere um valor antes da variável mantendo a variável no modelo.

Parameters

$modelostring
O template onde a inserção será feita.
$varstring
A variável/placeholder de referência.
$valorstring
O valor a ser inserido antes da variável.

Returns

string
Retorna o modelo com o valor inserido antes da variável.

modelo_tag_val

view source · line 199 ↗
modelo_tag_val(string $modelo, string $tag_in, string $tag_out): string

Extrai o conteúdo entre duas tags em um modelo.

Parameters

$modelostring
O template de onde o conteúdo será extraído.
$tag_instring
A tag de abertura.
$tag_outstring
A tag de fechamento.

Returns

string
Retorna o conteúdo entre as tags ou string vazia se não encontrado.

modelo_tag_in

view source · line 231 ↗
modelo_tag_in(string $modelo, string $tag_in, string $tag_out, string $valor): string

Substitui um bloco delimitado por tags incluindo as próprias tags.

Parameters

$modelostring
O template onde a substituição será feita.
$tag_instring
A tag de abertura do bloco.
$tag_outstring
A tag de fechamento do bloco.
$valorstring
O valor que substituirá todo o bloco (tags + conteúdo).

Returns

string
Retorna o modelo com o bloco substituído pelo valor.

modelo_tag_del

view source · line 267 ↗
modelo_tag_del(string $modelo, string $tag_in, string $tag_out): string

Remove um bloco delimitado por tags incluindo as próprias tags.

Parameters

$modelostring
O template de onde o bloco será removido.
$tag_instring
A tag de abertura do bloco a ser removido.
$tag_outstring
A tag de fechamento do bloco a ser removido.

Returns

string
Retorna o modelo sem o bloco especificado.

modelo_tag_troca_val

view source · line 305 ↗
modelo_tag_troca_val(string $modelo, string $tag_in, string $tag_out, string $valor): string

Substitui apenas o conteúdo entre as tags, preservando as tags.

Parameters

$modelostring
O template onde a substituição será feita.
$tag_instring
A tag de abertura (será preservada).
$tag_outstring
A tag de fechamento (será preservada).
$valorstring
O novo conteúdo que ficará entre as tags.

Returns

string
Retorna o modelo com o conteúdo entre as tags substituído.

modelo_abrir

view source · line 340 ↗
modelo_abrir(string $modelo_local): string

Carrega um arquivo de template e remove blocos de exclusão.

Parameters

$modelo_localstring
Caminho do arquivo de template a ser carregado.

Returns

string
Retorna o conteúdo do template com os blocos de exclusão removidos.

The Future is Hybrid: Human + AI.

Conn2Flow is the tool. If you need the Architect to design your company's strategy using this technology...

Hire Specialized Consulting