Search mechanism on symfony 5 - php

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.

Related

OctoberCMS - Overridden Blog Component (Rainlab Blog) Multiple Usage in Same Page

I am new to OctoberCMS and I am stuck now, I am facing issue to use my custom blog posts component (which overrides Rainlab blog posts) in the same page multiple times.
Say I have created an alias of default blogPosts to postLists and I defined my custom HTML structure and it is working well, no issues.
Now what I want is to use the postLists post structure in my page for three different categories and here I am stuck because when I pass variable to component like this - { % component 'postLists' categoryFilter='news' %} it does not work for the category filter and if I select a category from drag drop component UI it becomes global categoryFilter setting for the page.
This is my requirement.
My postList component code:-
{% set posts = __SELF__.posts %}
{% for post in posts %}
<div class="col-sm-6">
<div class="row">
<div class="col-sm-4 col-4 content_body_img">
<a href="{{ post.url }}">
{% if post.featured_images.count > 0 %}
<img class="media-object" src="{{ post.featured_images.first.getThumb(108, 108) }}" />
{% else %}
<img class="media-object" src="http://placehold.it/108x108" />
{% endif %}
</a>
</div>
<div class="col-sm-8 col-8">
<p>{{ post.title }}</p>
<!--location_date-->
<div class="location_date">
<ul>
<li><i class="fa fa-calendar"></i><span> {{ post.published_at|date('j F, Y') }}<span></li>
<li><i class="fa fa-map-marker"></i>Dubai</li>
</ul>
</div>
<!--location_date end -->
</div>
</div>
</div>
<!--content_body_img end -->
{% else %}
<div class="col-sm-6 col-6 col-lg-3">{{ noPostsMessage }}</div>
{% endfor %}
Please help me, any help will be very much appreciated.
Thanks Sanny
This is static Approach - I will post dynamic Approach as well give me some time
Best and possibly easy solution will be ( in case you just intend to show posts ) is to add 3 Post List component with Different Category filter option for each tab.
It should do your work
make sure this is optimal solution if you just need to show lists nothing else.

One Web Page Doesn't Show Up and With The Error - The character encoding of the HTML document was not declared

I've a project that uses Twig Template engine and every page of the project was working perfectly. Now suddenly from today, one of the pages doesn't show and got this - The character encoding of the HTML document was not declared. and here is the link - Website Link
. The page contains the following code and also with the required tags (Even though I've tried to do some modification but didn't work):
{% extends "fafc.base.html.twig" %}
{% set title = "First Aid Financial Consultants" %}
{% block title %} {{ title }} {% endblock %}
{% block head %}
{{ parent() }}
<link href="/assets/css/fadeSlider.css" rel="stylesheet" type="text/css"/>
{% endblock %}
{% block sliderarea %}
<section>
<!-- New Slider-->
<div class='csslider1 autoplay '>
<input name="cs_anchor1" id='cs_slide1_0' type="radio" class='cs_anchor slide' >
<input name="cs_anchor1" id='cs_slide1_1' type="radio" class='cs_anchor slide' >
<input name="cs_anchor1" id='cs_slide1_2' type="radio" class='cs_anchor slide' >
<input name="cs_anchor1" id='cs_slide1_3' type="radio" class='cs_anchor slide' >
<input name="cs_anchor1" id='cs_play1' type="radio" class='cs_anchor' checked>
<input name="cs_anchor1" id='cs_pause1_0' type="radio" class='cs_anchor pause'>
<input name="cs_anchor1" id='cs_pause1_1' type="radio" class='cs_anchor pause'>
<input name="cs_anchor1" id='cs_pause1_2' type="radio" class='cs_anchor pause'>
<input name="cs_anchor1" id='cs_pause1_3' type="radio" class='cs_anchor pause'>
<ul>
<li class="cs_skeleton"><img src="/assets/images/sliders/fafc/bright-future-loans.jpg" style="width: 100%;"></li>
<li class='num0 img slide'><img src='/assets/images/sliders/fafc/bright-future-loans.jpg'/></li>
<li class='num1 img slide'> <img src='/assets/images/sliders/fafc/credit-apply-now.jpg'/></li>
<li class='num2 img slide'> <img src='/assets/images/sliders/fafc/fafc-driven-success.jpg'/></li>
<li class='num3 img slide'> <img src='/assets/images/sliders/fafc/refer-earn.jpg'/></li>
</ul><div class="cs_engine"></div>
<div class='cs_bullets'>
<label class='num0' for='cs_slide1_0'> <span class='cs_point'></span>
<span class='cs_thumb'><img src='/assets/images/sliders/fafc/thumbnail/bright-future-loans.jpg' /></span></label>
<label class='num1' for='cs_slide1_1'> <span class='cs_point'></span>
<span class='cs_thumb'><img src='/assets/images/sliders/fafc/thumbnail/credit-apply-now.jpg'/></span></label>
<label class='num2' for='cs_slide1_2'> <span class='cs_point'></span>
<span class='cs_thumb'><img src='/assets/images/sliders/fafc/thumbnail/fafc-driven-success.jpg'/></span></label>
<label class='num3' for='cs_slide1_3'> <span class='cs_point'></span>
<span class='cs_thumb'><img src='/assets/images/sliders/fafc/thumbnail/refer-earn.jpg'/></span></label>
</div>
</div>
<!--
<div class="banner bann1">
<div class="flex-container">
<div class="flexslider">
<ul class="slides">
<li>
<img src="/assets/images/sliders/fafc/bright-future-loans.jpg" />
</li>
<li>
<img src="/assets/images/sliders/fafc/credit-apply-now.jpg" />
</li>
<li>
<img src="/assets/images/sliders/fafc/fafc-driven-success.jpg" />
</li>
<li>
<img src="/assets/images/sliders/fafc/refer-earn.jpg" />
</li>
</ul>
</div>
</div>
</div>
-->
</section>
{% endblock %}
{% block gridarea %}
{{ parent() }}
{% endblock %}
{% block grid %}
<ul>
<li>Your <span>Financial Health</span> Is Our <span>First Priority</span>.</li>
<li><img src="/assets/images/grid-tiles/infographics.jpg" alt="Store" title="View Infographics" /></li>
<li><img src="/assets/images/grid-tiles/fafc/img1.jpg" alt="" title=""/></li>
<li><img src="/assets/images/grid-tiles/fafc/img3.jpg" alt="" title=""/></li>
<li><img src="/assets/images/grid-tiles/articles.jpg" alt="Latest Articles" title="Latest Articles"/></li>
<li><img src="/assets/images/grid-tiles/resources.jpg" alt="Resources" title="Download Resources" /></li>
<li><img src="/assets/images/grid-tiles/fafc/img2.jpg" alt="" title=""/></li>
<li><img src="/assets/images/grid-tiles/videos.jpg" alt="Videos" title="Watch Videos"/></li>
</ul>
{% endblock %}
{% block verticlemenu %}
<ul>
<li>Personal Loans</li>
<li>Business Loans</li>
<li>Finance & Partnership</li>
<li>Chat With Us</li>
</ul>
{% endblock %}
{% block content %}
<section>
<div class="span1 section-border"></div>
<div class="wrapper">
<div class="fafclist">
<ul>
<li> <img src="/assets/images/dollar-icon.png" alt=""/>
<h3>Payday Express</h3>
<p>Get access to funds at the best interest rate with no guarantor required.</p>
<div class="button-left text-align" > CLICK HERE </div>
</li>
<li><img src="/assets/images/home-icon.png" alt="Home" />
<h3>Signature Executive</h3>
<p>Designed for our loyal clients. Fantastic offers at floor rates. Become a member today.</p>
<div class="button-left text-align" > CLICK HERE </div>
</li>
<li> <img src="/assets/images/currency-icon.png" alt="Currency" />
<h3>Premium Advantage</h3>
<p>Take Control of your future by accessing our regular loan facility. </p>
<div class="button-left text-align" > CLICK HERE </div>
</li>
<li> <img src="/assets/images/handshakesmall-icon.png" alt=""/>
<h3>Apply Today</h3>
<p>Take the opportunity. The time is now!!!<br/><br/></p>
<div class="button-left text-align" > CLICK HERE </div>
</li>
</ul>
</div>
</div>
</section>
<section class="dashed-border">
<div class="wrapper">
<!-- Container1-->
<div class="hb-contbtgd pb mrgn-bttm">
<aside class="half-width fafc">
<h2>Finance and Partnership</h2>
<div class="row">
<!-- <div class="image"> <img src="/assets/images/epaydayexpress-icon.png" alt="" /></div>-->
<div class="cntbox">Do you have a great idea but little or no funding to realize that dream? Let us assist you with the financial planning needed to get you on your way to success. Come in and speak with one of our expert advisors today.<br>
Read more </div>
</div>
</aside>
<aside class="half-width fafc">
<h2>Lease Financing</h2>
<div class="row">
<!--<div class="image"><img src="/assets/images/signature.png" alt="Signature"></div>-->
<div class="cntbox">Do you need capital or machinery for your small business, but don’t know where to turn? Let us purchase it for you. At First Aid Financials, your future is bright. Our payment terms are flexible and our rates are incomparable. <br>
Read more </div>
</div>
</aside>
</div>
</div>
</section>
<section class="mrtb">
<div class="wrapper">
<!-- Container-->
<div class="wrapper listing-box fafclib">
<ul>
<li>
<div class="fafc">
<h2>First Aid Financial Consultants</h2>
</div>
<p>Valid ID and TRN<br/><br/></p>
<p>Last 3 payslips or job letter<br/><br/></p>
<p>Recent Proof of Address<br/><br/></p>
<a class="btn" href="/{{ company_url }}/apply">Apply Now</a>
<div class="img"><img width="92" height="98" src="/assets/images/btn-arrow.png"></div>
</li>
<li class="red-gredential">
<div class="heading1">
<h2>Check out our same day loan</h2>
</div>
<p>Available within 24 hours<br/><br/></p>
<p>No guarantor needed<br/><br/></p>
<p>Convenient Online Application<br/><br/></p>
<div class="img"><img width="92" height="98" src="/assets/images/white-arrow01.png"></div>
</li>
<li class="waitfor"> <img src="/assets/images/what-you-are-banner.jpg" alt="What you are waiting for"/></li>
</ul>
</div>
</div>
</section>
{% endblock %}
This page inherits few things from other pages and checked if the page contains the appropriate meta tags. The following were included:
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
<meta content="utf-8" http-equiv="encoding">
I am not sure what kind of error is this and any idea to resolve would be highly appreciated.

twig break out of loop and then continue the rest in next div

I am trying to loop through an array of meeting objects each meeting on same date needs to be displayed inside its own div and if the date changes then that date meeting needs to be in next div so the output i am looking for is something like this
<div class="row">
<h2 class="date-heading">September 24</h2>
<div class="col4">Meeting 1 </div>
<div class="col4">Meeting 2 </div>
<div class="col4">Meeting 3 </div>
<div class="col4">Meeting 4 </div>
<div class="col4">Meeting 5 </div>
</div>
<div class="row">
<h2 class="date-heading">September 25</h2>
<div class="col4">Meeting 1 </div>
<div class="col4">Meeting 2 </div>
<div class="col4">Meeting 3 </div>
<div class="col4">Meeting 4 </div>
<div class="col4">Meeting 5 </div>
</div>
<div class="row">
<h2 class="date-heading">September 26</h2>
<div class="col4">Meeting 1 </div>
<div class="col4">Meeting 2 </div>
<div class="col4">Meeting 3 </div>
<div class="col4">Meeting 4 </div>
<div class="col4">Meeting 5 </div>
</div>
Now inside the loop i have access to a parameter of each object called request.isNewDate, this is set to yes as soon as the current loop has a different date than the previous loop, i think i can use this to achieve what i need but i am having a problem in the logic.
This is what my code looks like where I am looping, how can i break out of this loop if the request.isNewDate is yes and then start the rest inside a new div.
Any help will be appreciated.
<div class="row">
{% for request in pagination %}
<div class="col4">
<h5 class="">{{ request.getGuest.getFirstName }}</h5>
<h6 class="text-transform-none">{{ request.getGuest.getCollege }}<br>
{{ request.getGuest.getDegree }}<br>
({{ request.getGuest.getCourse }})
</h6>
</div>
</div>
Try this snipped code:
{% for request in pagination %}
{#
If is a new date, open a new div TAG and dump the data.
If the first element of the collection do not have this info
consider to use loop.index0 as OR operation.
#}
{% if request.isNewDate %}
<div class="row">
{# print and format the date #}
<h2 class="date-heading">{{ request.date }}</h2>
{% endif %}
{# Render data of an element, consider to wrap this data in a single twig and incude #}
<div class="col4">
<h5 class="">{{ request.getGuest.getFirstName }}</h5>
<h6 class="text-transform-none">{{ request.getGuest.getCollege }}<br>
{{ request.getGuest.getDegree }}<br>
({{ request.getGuest.getCourse }})
</h6>
</div>
{# remember to close the div #}
{% if request.isNewDate %}
</div>
{% endif %}
{% endfor %}
Hope this help
Perform the logic in the controller and pass the data to Twig separately.
You don't want that kind of logic buried in a template. It will become a maintenance headache in the future and doing that sort of thing leads to cluttered, difficult to read templates.

OctoberCMS: How to remove an item from todo list?

I was following this tutorial to learn how to create a TODO list. But it ends without explaining how to remove an item from the list. Could somebody please post a sample code for it?
Here is the content of Todo\default.htm:
<script type="text/javascript" src="{{ ['assets/vendor/jquery.min.js']|theme }}"></script>
{% framework %}
<form
data-request="{{ __SELF__ }}::onAddItem"
data-request-success="$('#inputItem').val('')"
data-request-update="'{{ __SELF__ }}::tasks': '#result'"
>
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Tasks assigned to: {{__SELF__.name}} </h3>
</div>
<div class="panel-body">
<div class="input-group">
<input name="task" type="text" id="inputItem" class="form-control" value=""/>
<span class="input-group-btn">
<button type="submit" class="btn btn-primary">Add</button>
</span>
</div>
</div>
<ul class="list-group" id="result">
{% partial __SELF__ ~ '::tasks' tasks = __SELF__.tasks %}
</ul>
</div>
</form>
And the content of tasks.htm partial:
{% for task in tasks %}
<li class="list-group-item">
{{ task }}
<button class="close pull-right">×</button>
</li>
{% endfor %}
I need to get the [X] button which removes a single task from the todo list working. My guess is that I should go with this:
{% for task in tasks %}
<li class="list-group-item">
{{ task }}
<button class="close pull-right" data-request="{{ __SELF__ }}::onDeleteItem">×</button>
</li>
{% endfor %}
I don't know though how to pass the id of each item to the onDeleteItem function.
Following is the code for default.htm
<form
data-request="{{ __SELF__ }}::onAddItem"
data-request-update="'{{ __SELF__ }}::tasks': '#result'"
data-request-success="$('#input-item').val('')"
>
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">To Do List</h3>
</div>
<div class="panel-body">
<div class="input-group">
<input type="text" id="input-item" class="form-control" value="" name="task" placeholder="What needs to be done?">
<span class="input-group-btn">
<button type="submit" class="btn btn btn-primary" data-attach-loading>Add</button>
</span>
</div>
</div>
<ul class="list-group" id="result">
{% partial __SELF__ ~ '::tasks' tasks = __SELF__.tasks %}
</ul>
</div>
Following is the code in Todo.php
public function onRun(){
//$this->tasks=Task::lists('title');
$this->tasks=Task::all();
}
public function onAddItem()
{
$taskName = post('task');
$task=new Task;
$task->title=$taskName;
$task->save();
$this->page['tasks']=Task::all();
}
public function onDeleteItem()
{
$id = post('id');
$task=Task::find($id);
$task->delete($id);
$this->page['tasks']=Task::all();
}
and following is the code for tasks.php partial
{% for task in tasks %}
<ul class="list-group">
<li class="list-group-item">{{task.title}}
<button type="button" class="close pull-right"
data-request="{{ __SELF__ }}::onDeleteItem"
data-request-update="'{{ __SELF__ }}::tasks': '#result'"
data-request-data="id:'{{task.id}}'"
>×</button>
</li>
</ul>
{% endfor %}
It works perfectly for me in case of any problem let me inform
The [X] Button should use:
data-request to tell the php ajax handler, which procedure to call
data-request-data to tell the php ajax handler, which data to use
data-request-update to tell the javascript ajax handler, which partial to update
<button
data-request="onDeleteItem"
data-request-data="deleteItem: '{{ task }}'"
data-request-update="'{{__SELF__}}::tasks': '#result'"
class="close pull-right">
&times
</button>
...and you will find the content of the task variable with
$taskToDelete=post('deleteItem');

How to create dynamic LI and DIV for template

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.

Categories