I want to call a component inside a component with a variable, like this:
Here's the code of the default.html->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
<div class="container">
<div class="row">
{% partial __SELF__ ~ "::category" category=__SELF__.category childscategory=__SELF__.childscategory%}
<div class="col-xs-3">
<strong>DATA</strong>
<ul class="list-group text-center">
{% partial __SELF__ ~ "::dates" files=__SELF__.files %}
</ul>
</div>
<div class="col-xs-3">
<strong>Nome do Ficheiro</strong>
<ul class="list-group text-center">
{% partial __SELF__ ~ "::files" files=__SELF__.files %}
</ul>
</div>
<div class="col-xs-3">
<strong>Descrição</strong>
<ul class="list-group text-center">
{% partial __SELF__ ~ "::description" files=__SELF__.files %}
</ul>
</div>
<div class="col-xs-1">
<strong>{{__SELF__.labelpresentation}}</strong>
<ul class="list-group text-center">
{% partial __SELF__ ~ "::download_1" files=__SELF__.files %}
</ul>
</div>
-> I WANT TO CALL THE COMPONENT HERE <-
</div>
</div>
If you want me to post more code like the .php, it's ok
Example: use the fileUploader component in my ApplicationForm component. In ApplicationForm class, add this:
public function init()
{
$component = $this->addComponent(
'Responsiv\Uploader\Components\FileUploader',
'fileUploader',
[
'deferredBinding' => true,
'maxSize' => $this->property('maxFileSize'),
'fileTypes' => $this->property('fileTypes'),
'placeholderText' => $this->property('placeholderText'),
]
);
$component->bindModel('cv', new Application());
}
And in the view (default.htm) of the ApplicationForm component use the initialized component like so:
{% component 'fileUploader' %}
Related
I am writing a diploma in symfony 5 and studying symfony in parallel. I reached the implementation of the search in the table. I have a search field
<div class="search__container">
<div class="search__block">
<img class="search__glass" src="{{ asset('images/search-glass.svg')}}">
<input class="search__field" type="text">
</div>
</div>
and the actual table itself, which is output as follows
<div class="table__body">
{% block table_items %}
{% for item in items %}
<div class="body__item">
<a class="item__detail" href="item.html"></a>
<img class="item__icon" src="images/icons/{{ item.extension }}.svg">
<div class="item__title">{{ item.fileName }}</div>
<div class="item__extension">{{ item.extension }}</div>
<div class="item__updated">{{ item.uploaded }}</div>
<div class="item__size">{{ item.size }}b</div>
<div class="item__act">
<span></span>
<span></span>
<span></span>
<div class="action__popap">
<ul class="actions__list">
<li class="act__item detail">
Detail
</li>
<li class="act__item delete">
Delete
</li>
<li class="act__item download">
Download
</li>
</ul>
</div>
</div>
</div>
{% endfor %}
{% endblock %}
</div>
I want to do a search by "item.fileName" without reloading the page. And when I started doing it, I was at a dead end, not knowing what to do. I can do this with a page reload, but as for me it is not very convenient.
So, how can i do this?
I hope you can help me or point me to the correct vector.
I want to pass data from my controller to the twig view.
this is my controller code:
class HomeController extends Controller
{
public function index($request, $response)
{
return $this->view->render($response, 'home.twig');
}
public function numbers($request, $response){
return $this->view->render($response, 'home.twig', ['test' => '1221']);
}
}
This is my home.twig code:
{% block content %}
<div id="wrapper">
<div class="content-wrapper container">
<div class="row">
<div class="col-sm-12">
<div class="page-title">
<h1>Numbers for {{ test }} <small></small></h1>
<ol class="breadcrumb">
<li><i class="fa fa-home"></i></li>
<li class="active">Data</li>
</ol>
</div>
</div>
</div><!-- end .page title-->
<div class="row">
<div class="col-sm-12">
{{ abs }}
</div>
</div>
</div>
</div>
{% endblock %}
The value 1221 that is set under test is not shown on the page when rendered.
What am I missing?
I'm working on a wordpress plugin using herbert. I have two controllers, the one (ClientController) which is called via panel and the second one(TimelineController) is an API controller for saving new data on the time line and is called via AJAX request using routes.
Here are my two controllers
ClientController
public function edit(Http $request)
{
$client = $this->clientsRep->find($input["id"]);
$timeline = $client->timeline;
return view('#AdminViews/edit.twig',compact('client', 'timeline'));
}
TimelineController
public function store(Http $request)
{
if($request->ajax())
{
if (is_user_logged_in())
{
$class = ucfirst($request->get('type'));
$c = 'Testing\\HelpedClasses\\TimelineLib\\'.$class;
$activity = new $c();
$activity = $activity->saveActivity($request);
if (is_array($activity))
{
$type = $activity["type"];
$activity = Activities::find($activity["activity_id"]);
$returnHTML = herbert('twig')->render('#AdminViews/edit/timeline_partials/timeline-row.twig', [
'activity' => $activity,
]);
return new JsonResponse(['success' => true, 'html' => $returnHTML, 'type' => $request->get('type'));
}
}
}
}
Here are the Models with their relations
class Client extends Model
{
public function timeline()
{
return $this->hasOne('Test\Models\Admin\Timeline', 'timeline_client_id', 'ID');
}
}
class Activities extends Model
{
public function clientNote()
{
return $this->hasOne('Test\Models\Admin\Notes', 'notes_timeline_activities_id', 'ID');
}
}
Here are the views
edit.twing
<div class="wrap">
<h1>Edit: {{client.clientMeta.name.value }} {{client.clientMeta.name.lastname }}</h1>
<div class="postbox ">
<ul class="nav nav-pills">
<li class="active">Account</li>
<li>Activity</li>
</ul>
<div class="inside">
<div class="tab-content clearfix">
<div class="tab-pane active" id="1a">
{% include '#AdminViews/edit/edit.twig' %}
</div>
<div class="tab-pane" id="timeline">
{% include '#AdminViews/edit/timeline.twig' %}
</div>
</div>
</div>
</div>
</div>
timeline.twig
<h3>Activity</h3>
<div class="timeline row">
<div class="col-sm-12 col-md-4 col-md-push-8">
Add Note <i class="fa fa-sticky-note"></i>
</div>
<div class="col-sm-12 col-md-8 col-md-pull-4 timeline-section">
{% if timeline is not null %}
<ul class="timeline">
{% for activity in timeline %}
{% include '#AdminViews/edit/timeline_partials/timeline-row.twig' %}
{% else %}
<li class="empty-list">Looks like you have no addresses added.</li>
{% endfor %}
</ul>
{% else %}
<p class="empty-list">Looks like you don't have any timeline yet for this customer.</p>
{% endif %}
</div>
</div>
timeline-row.twig
<li>
<div class="direction-l"><span class="time-wrapper"><span class="time">{{activity.updated_at}}</span></span></div>
<div class="direction-r">
<div class="flag-wrapper">
<span class="flag">
{% include '#AdminViews/edit/timeline_partials/timeline-row-'~ activity.timeline_meta_key ~ '.twig' %}
</span>
</div>
</div>
</li>
and here is a sample of activity.timeline_meta_key value: timeline-row-note.twig
<span class="timeline-key"> <i class="fa fa-bell-o"></i>{{activity.timeline_meta_key}}</span>
<div class="clearfix"></div>
{% if activity.clientNote %}
<p class="note-subject">{{activity.clientNote.notes_subject}}</p>
{% endif %}
{% if activity.clientNote %}
<p class="note-desc">{{activity.clientNote.notes_description}}</p>
{% endif %}
Now if I call the ClientController it shows me fine the values {{activity.clientNote.notes_subject}} and {{activity.clientNote.notes_description}}
If now I call the TimelineController is not printing the variables that I already mentioned, I did a dd() in the twig file and it says that the variable is null, but if I do dd() before
$returnHTML = herbert('twig')->render('#AdminViews/edit/timeline_partials/timeline-row.twig', [
'activity' => $activity,
]);
and after Activities::find($activity["activity_id"]); the two variables have the correct value. Does anyone knows why is not showing me the values of the relation activity.clientNote in the twig files if I'm do an ajax call?
Thank you
Is there are way I can create an easily maintainable for loop in Twig that works with Bootstrap's layout?
I'm using bootstrap's row functionality, meaning that each row has a div of class "row". This makes things tricky in twig, because I have no way of entering these header divs.
For example, my main page will have several articles, and extends the skeleton template, as shown below. Is there any way I can use this skeleton base and use it multiple times in a for loop?
I've tried by adding the Article block, but it overrides everything inside. Do I have to create another template for this to work?
<div id="main" class="container-fluid">
{% block article %}
<div class="row">
<div class="col-md-3"></div>
<div id="title" class="col-md-6">
{% block title %}
{% endblock title %}
</div>
<div class="col-md-3"></div>
</div>
<div class="row">
<div class="col-md-1"></div>
<div id="left-nav" class="col-md-2">
{% block left_nav %}
{% endblock left_nav %}
</div>
<div class="col-md-6" id="content">
{% block content %}
{% endblock content %}
</div>
<div id="right-nav" class="col-md-2">
{% block right_nav %}
{% endblock right_nav %}
</div>
<div class="col-md-1"></div>
</div>
{% endblock article %}
</div>
How do I iterate and create multiple "Articles" in this context?
Using parent() isn't helpful because it'll just print the start and end tags, wheras I need them to be placed around the correct sections, otherwise the rows won't work.
In other words, in a for loop context, how can I change the values of variables inside child blocks within a parent block?
Apologies if this is unclear, I found it hard to put into words.
Edit:
I know the existence of for loops in twig, I am just unsure of how to implement a solution to this particular problem.
As a simple example of the skeleton template and its output:
Template
<div class="row">
<div class="title">
{% block title %}{% endblock %}
</div>
<div id="content">
{% block content %}{% endblock %}
</div>
</div>
Output
<div class="row">
<div class="title">
This is the first post.
</div>
<div id="content">
Post 1
</div>
</div>
<div class="row">
<div class="title">
This is the second post.
</div>
<div id="content">
Post 2
</div>
</div>
I found a solution that is fairly maintainable, as it still extends the skeleton template, but is flexible enough to support for loops inside a block.
Skeleton
<div id="main" class="container-fluid">
{% block article %}
<div class="row">
<div class="col-md-3"></div>
<div id="whitespace" class="col-md-6">
{% block title %}
{% endblock title %}
</div>
<div class="col-md-3"></div>
</div>
<div class="row">
<div class="col-md-1"></div>
<div id="left-nav" class="col-md-2">
{% block left_nav %}
{% endblock left_nav %}
</div>
<div class="col-md-6" id="content">
{% block content %}
{% endblock content %}
</div>
<div id="right-nav" class="col-md-2">
{% block right_nav %}
{% endblock right_nav %}
</div>
<div class="col-md-1"></div>
</div>
{% endblock article %}
</div>
Article list
{% extends 'skeleton.php' %}
{% block article %}
{% for post in posts %}
<div class="row">
{# Start title #}
<div class="col-md-3"></div>
<div id="title" class="col-md-6">
{{post.title}}
</div>
<div class="col-md-3"></div>
{# End title #}
</div>
<div class="row">
<div class="col-md-1"></div>
{# Start left-nav #}
<div id="left-nav" class="col-md-2">
{{post.left}}
</div>
{# end left-nav #}
{# Start content #}
<div class="col-md-6" id="content">
{{post.getBody}}
</div>
{# end content #}
{# start right-nav #}
<div id="right-nav" class="col-md-2">
{{post.right}}
</div>
{# end right-nav #}
<div class="col-md-1"></div>
</div>
{% endfor %}
{% endblock article %}
{% foreach article in articles %}
<div class="row">
<div class="title">
{{ article.title }}
</div>
<div id="content">
{{ article.content }}
</div>
</div>
{% endfor %}
Is the template assuming articles is an array containing arrays with keys title and content
I want to know what language can make my template being dynamic. Example HTML sturtcure
<div id="tabs">
<ul class="tabs">
<li>Header</li>
<li>Navigation</li>
<li>Layout & Colors</li>
<li>Optimization</li>
<li>Miscellaneous</li>
</ul>
<form method="post" action="options.php">
<div class="tab-container">
<div id="tabs-1" class="tab-content">Header</div>
<div id="tabs-2" class="tab-content">Navigation</div>
<div id="tabs-3" class="tab-content">Layout & Colors</div>
<div id="tabs-4" class="tab-content">Optimization</div>
<div id="tabs-5" class="tab-content">Miscellaneous</div>
</div>
</form>
</div>
I want the LI and DIV
<li>Header</li>
<div id="tabs-1" class="tab-content">Header</div>
Can be dynamic without write it one by one. How to do that?
jQuery Templates works best in this scenario.
Check the doc #:
http://api.jquery.com/jQuery.template/
I'd use Python, more specifically Flask. Here's a maybe-working template. I'm guessing your element's names are stored in a list returned by get_titles:
<div id="tabs">
<ul class="tabs">
{% for index in get_titles|length %}
<li>{{ titles[index] }}</li>
{% endfor %}
</ul>
<form method="post" action="options.php">
<div class="tab-container">
{% for index in titles|length %}
<div id="tabs-{{ index + 1 }}" class="tab-content">{{ titles[index] }}</div>
{% endfor %}
</div>
</form>
</div>
But then again, this might be a bit overkill.