I'm creating a website using GRAV CMS and I stumbled upon a problem that I need help with... I created a page that I want to list out all pdf-files that I upload in GRAV. I want the output to look something like that:
The pure hardcoded HTML for this looks like that:
<div class="container pt-5 pb-5">
<div class="row">
<div class="col-6">
<ul class="downloads">
<li class="download-item pb-3">
<i class="fas fa-file-pdf fa-lg"></i>
<a href="./assets/downoads/file.pdf" class="action-btn m-0" download</a>
.
. etc...
.
</li>
</ul>
</div>
</div>
</div>
and the <li></li> is repeated as many times as the number of pdf-s...
The grav HTML and Twig combo looks like this:
<div class="container pt-5 pb-5">
<div class="row">
<div class="col-12">
<ul class="downloads">
{% for pdf in page.media %}
<li class="download-item pb-3">
<i class="fas fa-file-pdf fa-lg"></i>
<a href="{{ pdf.url }}" class="action-btn m-0" download></a>
</li>
{% endfor %}
</ul>
</div>
</div>
</div>
Now this code does not work, it generates this error:
Twig_Error_Syntax:
Unexpected token "punctuation" of value "." ("operator" expected with value "in").
I have also tried this:
<div class="container pt-5 pb-5">
<div class="row">
<div class="col-12">
<ul class="downloads">
{% for manuals in page.media %}
<li class="download-item pb-3">
<i class="fas fa-file-pdf fa-lg"></i>
{% set pdf = manuals.media %}
<a href="{{ pdf.url }}" class="action-btn m-0" download></a>
</li>
{% endfor %}
</ul>
</div>
</div>
</div>
and this:
<div class="container pt-5 pb-5">
<div class="row">
<div class="col-12">
<ul class="downloads">
<li class="download-item pb-3">
<i class="fas fa-file-pdf fa-lg"></i>
<a href="{{ page.media.url('/pdf') }}" class="action-btn m-0" download></a>
</li>
</ul>
</div>
</div>
</div>
Both of these result didn't generate an error like the above... the page loaded but in inspect element mode the <a></a> tag was empty (looked like this):
How can I achieve this or what is wrong with my code?
<div class="container pt-5 pb-5">
<div class="row">
<div class="col-12">
<ul class="downloads">
<?PHP
$path = "./filespath/"; //set the path of the folder that contains the files
$dir_handle = #opendir($path) or die("Unable to open $path");
while ($file = readdir($dir_handle))
{if($file!="." && $file!=".." && is_file($path.$file)){$f[] = $file;}}
closedir($dir_handle);
if(count($f)>0){
sort($f);//Set an order of the files
$newpath=substr($path,2);//this takes out the ./ of the path
foreach ($f as $val) {
echo '
<li class="download-item pb-3">
<i class="fas fa-file-pdf fa-lg"></i>
<a href="'.$newpath.$val.'" class="action-btn m-0" download>'.substr($val,0,-4).'</a><br>
</li>
';
}
}
?>
</ul>
</div>
</div>
</div>
I dont know how GRAV works, but this PHP code should help you. You only have to change the filespath where your files are located.
The path of folders where your files are located ex: falconimogollon.com/here/there/filesarehere/ you only set $path = "./here/there/filesarehere/";
If you need further help, reply me. Good Luck
Related
enter image description hereI'm working on Ecommerce Website that sells Coffee and my problem is that the only working plus and minus button is the first coffee. The plus and minus buttons on the others are not functioning. Is it about the for statement where I'm wrong? or the structure of the html isn't right.
I've copied some of the code on cart.html file to make the product page had the option of adding products to the cart and also has a proceed button to the checkout page. The before structure of the site was you click on the image of a product and directed to the addtocart page then to the checkout page.`{% extends 'app/base.html' %}
{% load static %}
{% block title %}Category{% endblock title %}
{% block main-content %}
<div class="container my-5">
<div class="row">
<div class="col-sm-8">
<div class="card">
<div class="card-body">
{% for prod in product %}
<div class="row">
<div class="col-sm-3 text-center align-self-center"><img src="{{prod.product_image.url}}" alt="" srcset="" class="img-fluid img-thumbnail shadow-sm" height="150" width="150"></div>
<div class="col-sm-9">
<div>
<h5>{{prod.title}}</h5>
<p class="mb-2 text-muted small">{{prod.description}}</p>
<div class="my-3">
<label for="quantity">Quantity:</label>
<a class="minus-cart btn" pid={{product.id}}><i class="fas fa-minus-square fa-lg"></i></a>
<span id="quantity">{{quantity}}</span>
<a class="plus-cart btn" pid={{product.id}}><i class="fas fa-plus-square fa-lg"></i></a>
</div>
<div class="d-flex justify-content-between">
<a href="#" class="remove-cart btn btn-sm btn-secondary mr-3" pid={{prod.id}}>Remove item </a>
<p class="mb-0"><span><strong>₱ {{prod.discounted_price}}</strong></span></p>
</div>
</div>
</div>
</div>
<hr class="text-muted">
{% endfor %}
</div>
</div>
</div>
<div class="col-sm-4">
<div class="card">
<div class="card-body">
<h3>The Total Amount </h3>
<ul class="list-group">
<li class="list-group-item d-flex justify-content-between align-items-center border-0 px-0 pb-0" >Amount<span id="amount">₱ {{amount}}</span></li>
<li class="list-group-item d-flex justify-content-between align-items-center px-0">Shipping<span>₱ 144</span></li>
<li class="list-group-item d-flex justify-content-between align-items-center border-0 px-0 mb-3">
<div>
<strong>Total</strong>
</div>
<span id="totalamount"><strong>₱ {{totalamount}}</strong></span>
</li>
</ul>
<div class="d-grid">Place Order</div>
</div>
</div>
</div>
</div>
</div>
{% endblock main-content%}
`
am getting this weird bug whereby css styles are only applying to the first 2 items in my foreach loop.here is my code.
//html code
<div class="row">
#if ($housescategory->isEmpty())
<div class="col-lg-4">
No houses Found At the Moment
</div>
#else
#foreach ($housescategory as $rentalhse)
<div class="col-lg-4">
<section class="card hsecard">
<figure>
<div class="img-overlay hot-home">
#if($rentalhse->vacancy_status==1)
<span class="badge badge-info p-2 rounded-0 statusbadge">Vacants Available</span>
#elseif($rentalhse->vacancy_status==2)
<span class="badge badge-success p-2 rounded-0 statusbadge">Fully Booked</span>
#endif
<img src="{{ asset ('imagesforthewebsite/rentalhouses/rentalimages/medium/'.$rentalhse->rental_image) }}" alt="{{ $rentalhse->rental_name }}">
</div>
{{ $rentalhse->id }}<figcaption>{{ $rentalhse->rental_name }}
</figcaption>
<div class="pricelocation" style="display: flex;
justify-content: space-between;">
<section class="location">
<a class="disabled font-italic h6"><i class="fa fa-map-marker"></i>{{ $rentalhse->houselocation->location_title }}</a>
</section>
<section class="pricelink">
<span class="btn btn-dark">sh.{{ $rentalhse->monthly_rent }}</span>
</section>
</div>
</figure>
<div class="card-content">
<p>{!! Str::limit($rentalhse->rental_details, 80)!!}</p>
<section class="icons-home">
<div class="name-icon">
#if ($rentalhse->cctv_cameras == 'yes')
<span>CCtv Security Cameras</span>
<div class="icon">
<i class="fa fa-camera-retro"></i>
<span>Available</span>
</div>
#endif
</div>
<div class="name-icon">
#if ($rentalhse->parking == 'yes')
<span>Parking</span>
<div class="icon">
<i class='fas fa-parking'></i>
<span>Available</span>
</div>
#endif
</div>
<div class="name-icon">
#if ($rentalhse->generator == 'yes')
<span>Backup Generator</span>
<div class="icon">
<i class="fa fa-bolt"></i>
<span>Available</span>
</div>
#endif
</div>
</section>
</div>
<div class="viewprice" style="display: flex;
justify-content: space-between; margin:0px !important;">
<section class="viewlink">
Contact Admin
</section>
<section class="viewlink">
<a class="btn-sm btn-warning" href="{{ url('rentalhse/'.$rentalhse->rental_slug.'/'.$rentalhse->id) }}" role="button" >
View Details
</a>
</section>
</div>
</section>
</div>
#endforeach
#endif
here its how it looks like in the page .here the paragraph starts getting itaicised which is a different style from the first one.. here is the other part here the column gets smaller different from the set one in the row.its been giving me headache i havent understood why its coming up.
I have django template file called card.html
In this file the anchor tag is on the outside.
<a class="url d-block" href="{% if content_type == 'book' %} {% url 'book' content.id|default:1 %} {% else %} {% url 'article' content.id|default:1 %} {% endif %}">
<div class="card d-flex flex-column border border-1 rounded">
<div class="p-5 bg-light">
<img src="{{ content.thumbnail }}" class="thumbnail img-fluid rounded">
</div>
<div class="flex-grow-1 p-4 border-top border-1">
<h3 class="category fs-5 text-secondary">{{ content.category.first }}</h3>
<h2 class="title fs-4 mb-2 text-dark">{{ content.title }}</h2>
{% if content_type == "book" %}
<a class="book-author fs-5 fw-bold" href="https://www.google.com/search?q={{content.book_author|default:''}}">By {{ content.book_author }}</a>
<h3 class="author fs-5 text-dark">Summarized by {{ content.author }}</h3>
{% else %}
<h3 class="author fs-5 text-dark">Created by {{ content.author }}</h3>
{% endif %}
</div>
<div class="flex-shrink-1 pt-3 d-flex justify-content-evenly border border-1">
<p class="date-created d-inline">{{ content.date_created }}</p>
<i class="fa-solid fa-star mt-1"></i>
<i class="fa-solid fa-ellipsis-vertical mt-1"></i>
</div>
</div>
</a>
card.html is included in this template (the div is inside a body).
<div id="list-container" class="d-flex flex-wrap justify-content-center gap-4 pb-5 px-5">
{% for content in content_list %}
{% include "app/card.html" with visibility="visible" %}
{% empty %}
<h2>No {{ content_type }} for now..</h2>
{% endfor %}
</div>
When rendered, it looks like this.
The anchor tag somehow close by itself and got inside the div.
<a class="url" href=" /books/1 "></a>
<div class="card d-flex flex-column border border-1 rounded">
<a class="url" href=" /books/1 ">
<div class="p-5 bg-light">
<img src="img.jpg" class="thumbnail img-fluid rounded">
</div>
</a>
<div class="flex-grow-1 p-4 border-top border-1">
<a class="url" href=" /books/1 ">
<h3 class="category fs-5 text-secondary">Example Category</h3>
<h2 class="title fs-4 mb-2 text-dark">Title</h2>
</a>
<a class="book-author fs-5 fw-bold" href="https://www.google.com/search?q=Name">By Name</a>
<h3 class="author fs-5 text-dark">Summarized by Archer</h3>
</div>
<div class="flex-shrink-1 pt-3 d-flex justify-content-evenly border border-1">
<p class="date-created d-inline">May 3, 2022, 9 a.m.</p>
<i class="fa-solid fa-star mt-1"></i>
<i class="fa-solid fa-ellipsis-vertical mt-1"></i>
</div>
</div>
You cannot use <a> tag inside <a> tag. HTML don't allow nested tag.
You can use onclick event but you have to check with javascript which element clicked because parent element is a wrapper.
I have to hide some button in an html page and for this I wanted to use a line that is located in another html file of mine, the ng-if="category.layers_count > 0".
enter image description here
But when I tried to put it in my other file, it doesn't work and I don't know why.
This is how I tried to do it.
{% verbatim %}
<div ng-repeat="category in categories"</div>
{% endverbatim %}
<div ng-if="category.layers_count > 0">
<div class="col-xs-4 col-sm-3 col-md-2 col-lg-1">
<a target="_self" href="{% url "search" %}?limit=100&offset=0&category__identifier__in=biota">
<div class="category" data-toggle="tooltip" data-placement="auto"
title="{% trans "Flora and/or fauna in natural environment. Examples: wildlife, vegetation, biological sciences, ecology, wilderness, sealife, wetlands, habitat." %}">
<i class="fa fa-leaf fa-3x"></i>
<h4>{% trans "Biota" %}</h4>
</div>
</a>
</div>
</div>
I have pasted a jsfiddle into my webpage and it doesn't work. Here is the jsfiddle. Pasted the CSS and javascript into the appropriaate places. There seem to be no errors on the console related to the link or popup.
All the link seems to do is to reload the current page.
Here is my HTML :
<div class="container">
<div class="row">
<div class="col-lg-8 col-md-8">
<!-- POST -->
{% for entry in entries %}
<div class="panel panel-default">
<div class="panel-body">
<div class="media media-clearfix-xs-min">
<div class="media-left">
<a href="lesson.html">
<span class="media-object icon-block bg-default"><i class="fa fa-github"></i></span>
</a>
</div>
<div class="media-body">
<h3 class="media-heading h4">{{ entry.title }}</h3>
<p class="small text-muted">
<!-- <i class="fa fa-clock-o fa-fw"></i> time since post -->
Open PopUp
<div class="popup-box" id="popup-box-1">
<div class="close">X</div>
<div class="top">
<h2>Sample Header</h2>
</div>
<div class="bottom">
<p><h1>Sample Text</h1></p>
</div>
</div>
<i class="fa fa-user fa-fw"></i> {{entry.user_name}}
<i class="fa fa-calendar fa-fw"></i> {{entry.date_posted}}
</p>
{% for tag in entry.tagList %}
<span class="label label-default">{{tag}}</span>
{% endfor %}
</div>
</div>
</div>
</div>
{% else %}
<em>No entries!</em>
{% endfor %}
</div>
</div>
</div>
Sorry, here, I should have tested more.
I thought I had pasted the javascript in the right file, but I didn't. Once I pasted the js in the right file, it worked fine.