how add meta description in tpl file - smarty

I need to add meta description from content
I have main.tpl and there is
<meta name="author" content="Kuzdrowiu.pl">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no" >
<link rel="stylesheet" href="./w3css.css">
<title>{$tresc.title} | Medycyna Naturalna</title>
The content is taken from this code:
<div id="content_middle">{include file="$content"}</div>
By entering the code below I can call the meta description but only with the html code. How can I do it differently? I've been sitting here for 3 days and nothing is working properly.
<meta name="description" content='{$tresc.content}'>
Please help

Maybe if-else condition help you:
{if $smarty.server.REQUEST_URI eq '/URL-1'}
<meta name='description' content='YOUR-DESCRIPTION-1'>
{elseif $smarty.server.REQUEST_URI eq '/URL-2'}
<meta name='description' content='YOUR-DESCRIPTION-2'>
{/if}

Related

js file not loading giving ERR_ABORTED 404

I have a Laravel/Vue3 project. For some reason I cannot get the right link to public/js/app.js.
My blade file:
<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Laravel</title>
</head>
<body>
<div id="app">
<map-app/>
</div>
<script src="{{asset('js/app.js')}}"></script>
</body>
</html>
In my .env file:
APP_URL=https://www.evenuitrusten.nl
ASSET_URL=${APP_URL}/bankjesserver/public
I then get the error:
GET https://www.evenuitrusten.nl/bankjesserver/public/js/app.js net::ERR_ABORTED 404
Where index.html is:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Laravel</title>
</head>
<body>
<div id="app">
<map-app/>
</div>
<script src="https://www.evenuitrusten.nl/bankjesserver/public/js/app.js"></script>
</body>
</html>
On my server, the url to app.js is
/home/blabla/domains/evenuitrusten.nl/bankjesserver/public/js
The URL in the script tag looks correct. Why am I getting a 404?
I tried all kinds of variations of Asset_URL, but non of them worked.
I tried to simplify the problem bij putting a test.js file in the same folder as my maps.blade.php. This file looks like:
<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Laravel</title>
</head>
<body>
<div id="app">
<map-app/>
</div>
<script type='text/javascript' src='./test.js'></script>
<script type='text/javascript' src='{{ asset('js/app.js') }}'></script>
</body>
</html>
But also this line leads to a 4040 and teh test.js is not downloaded.

Undefined variable: header (View: C:\blog\resources\views\pages\welcome.blade.php)

I am getting the below error when running application,
Undefined variable: header (View: C:\blog\resources\views\pages\welcome.blade.php)
My getIndex() function in Controller:
public function getIndex(){
\View::make('pages/welcome')->nest('header', 'layout.header');
return view('pages/welcome');
}
My welcome.blade.php
{{ $header }}
<body>
....
</body>
My _partial/header.blade.php,
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" href="../../favicon.ico">
<title>Blog Template for Bootstrap</title>
<!-- Bootstrap core CSS -->
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="{{ asset('css/style.css') }}" rel="stylesheet">
</head>
After following the answer, the html looks like,
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" href="../../favicon.ico">
<title>Blog Template for Bootstrap</title>
<!-- Bootstrap core CSS -->
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="http://127.0.0.1:8000/css/style.css" rel="stylesheet">
</head>
You're creating a view with a nested subview, then creating & returning a totally new view without the nested subview instead:
public function getIndex(){
\View::make('pages/welcome')->nest('header', 'layout.header');
return view('pages/welcome');
}
Should be
public function getIndex(){
return \View::make('pages/welcome')->nest('header', 'layout.header');
}
Note that view() is an alias of \View::make().
You can prevent the HTML from being escaped by using {!! $header !!} instead.
With Laravel 5+ development, you should be using Components and Slots to inject templates into your views instead.

extending fragments in Thymeleaf

I have the following fragment. I'm trying to extend the base fragment "head" with the open graph tags... but the rendered page contains only tags from fragments/head, with the og ones.
How can I add more tags to a fragment?
<head th:include="fragments/head :: head">
<!-- You can use Open Graph tags -->
<meta property="og:url" th:content="${url}" />
<meta property="og:type" content="website" />
<meta property="og:title" content="GUApp" />
<meta property="og:description" th:content="${description}" />
<!--<meta property="og:image" content="http://www.your-domain.com/path/image.jpg" />-->
</head>
<head th:fragment="head" xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
....
</head>
The easiest option is to pass additional tags as in Flexible layouts documentation demo.
Thanks to fragment expressions, we can specify parameters for
fragments that are not texts, numbers, bean objects… but instead
fragments of markup.
This allows us to create our fragments in a way such that they can be
enriched with markup coming from the calling templates, resulting in a
very flexible template layout mechanism.
index.html
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head th:include="header :: head(~{::meta})">
<!-- You can use Open Graph tags -->
<meta property="og:url" th:content="${url}"/>
<meta property="og:type" content="website"/>
<meta property="og:title" content="GUApp"/>
<meta property="og:description" th:content="${description}"/>
</head>
...
header.html
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head th:fragment="head(meta)">
<!-- some default styles -->
<link href="base.css" rel="stylesheet" />
<!--/* Per-page placeholder for additional meta tags */-->
<th:block th:replace="${meta}" />
</head>
...
Result html:
<!DOCTYPE html>
<html lang="en">
<head>
<link href="base.css" rel="stylesheet" />
<meta property="og:url"/>
<meta property="og:type" content="website"/>
<meta property="og:title" content="GUApp"/>
<meta property="og:description"/>
</head>
...

Code Igniter lose charset

I'm using codeigniter but it loses charset every time.
What can cause this?
For example:
At my address bar
www.abc.com/def
www.abc.com/def/
My db is UTF-8
My config file - $config['charset'] = 'ISO-8859-1';
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title></title>
<link rel="stylesheet" href="css/main.css">
</head>
<body>
</body>
</html>
take a look at meta charset part

Meta Tags Inside MasterPage Output On One Line

I like clean code and I'm sure most developers do. I am coming across an issue where my Meta tags are all appearing on ONE line all together and not on separate lines.
I have a file called "client.master" and here is code for the header:
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="default" />
<meta name="format-detection" content="telephone=no" />
<script src="/scripts/script1.min.js" type="text/javascript"></script>
<script src="/scripts/script2.min.js" type="text/javascript"></script>
<link rel="apple-touch-icon" href="/images/home-screen.png" />
<link rel="apple-touch-startup-image" href="/images/home-startup.png" />
<link href="/css/thirdparty/xxxxx.min.css" type="text/css" rel="stylesheet" />
<link href="/css/design.css" type="text/css" rel="stylesheet" />
<asp:ContentPlaceHolder ID="headContent" runat="server">
</asp:ContentPlaceHolder>
</head>
That looks very clean and nice. However, when I view the source of the page, the output shows the <meta> tags and the <link> tags all on one line. The script tags are not.
Here is the output of my code:
<!DOCTYPE html>
<html>
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" /><meta name="apple-mobile-web-app-capable" content="yes" /><meta name="apple-mobile-web-app-status-bar-style" content="default" /><meta name="format-detection" content="telephone=no" />
<script src="/scripts/script1.min.js" type="text/javascript"></script>
<script src="/scripts/script2.min.js" type="text/javascript"></script>
<link rel="apple-touch-icon" href="/images/home-screen.png" /><link rel="apple-touch-startup-image" href="/images/home-startup.png" /><link href="/css/thirdparty/xxxxx.min.css" type="text/css" rel="stylesheet" /><link href="/css/design.css" type="text/css" rel="stylesheet" />
<title>
Login
</title></head>
Notice the <meta> and <link> tags are both on a single line AND the <title> tag has line breaks.
Here is the HTML for the default.aspx page for the Title:
<asp:Content ID="title" runat="server" ContentPlaceHolderID="title">
Login
</asp:Content>
My assumption is because the <meta> tags and <link> tags are self enclosed and the <script> tags end with </script>.
Is the only way to resolve this issue to close my <meta> tags with </meta>. Which way is to be considered the standard when closing meta and link tags? or script tags?
Thanks in advance for your help!
If you really want to follow the spec, link and meta are void elements, they can't have a closing tag, if your DOCTYPE is HTML5, you can use the selfclosing tag <meta ..../> but the default way would be to use it only as a start tag, that is a correct conforming use as empty elements don't need an end tag (void ones, as I said, can't have it).
Script is not a void element, but is an empty one, so you can use only the start tag, the self-closing tag or both start and end tags.
Note that for an element to have a content model of type empty really means it may be empty, not that it should; that would probably be what it is called void.
As to why the asp parser does that to your metas, I can't think of a reason. I understand your preference for clean code, but if it is of any help, try to think that at least that bug contributes to a filesize decrease :o)
Bear in mind that all of this applies to HTML5, XHTML treats void and empty models differently.

Resources