Laravel : add section only if it exists in child - laravel-5.4

I've defined an app.blade.php containing header ,footer , and a section for content:
<html>
<head>
....
<title>#yield('title')<title>
<meta type='description' content="#yield('description')">
...
</head>
<body>
..
#yield('content')
..
</body>
</html>
in all child blade that i extend app.blade i have to define a value for description , else it will be empty and google would show no description for it in search results:
#extend('app')
#section('title','a title')
#section('description','something')
#section('content')
....
#endsection
how can i prevent description meta to be included in head , when i have not defined it in child blade that has extended app.blade?

i should use hasSection directive , as described here

Related

Dynamically change translated page title - Svelte

I've made a page in Svelte. I've provided translations in two languages and it works fine. Now, I want the title on each page to change, and what's more, I want it translated into the current language of the page. I've tried with two-way binding, but I think, that I make something wrong. Minimal example:
//../components/meta-title.svelte
<svelte:head>
<title>{title}</title>
</svelte:head>
<script>
export let title = "default title for page"
</script>
//../pages/_layout.svelte
<Meta bind:title={$_('title.companyTitle')} /> //doesn't work
<Navigation items={items}/>
<div>
<slot/>
</div>
<Footer contact={contact}/>
//../pages/company.svelte
<LeadSection classes="lg:flex-row-reverse -mt-24">
<div slot="header">
{ $_('pages.company.header') }
</div>
...
</LeadSection>
Any ideas how to make this?
My understanding is: you want to dynamically set the title. To achieve this you don't have to use two way binding. Two way binding is meant to write back to a variable in the parent component. The "variable" you are trying to bind to is not a variable but a store which can't be used for binding. Just pass the title in as a normal prop and it should work:
//../components/meta-title.svelte
<svelte:head>
<title>{title}</title>
</svelte:head>
<script>
export let title = "default title for page"
</script>
//../pages/_layout.svelte
<Meta title="This is a dynamic title" />
...
If you are using routing "svelte-routing" then you must have created the separate pages e.g "Home.svelte", "About.svelte".
On each page add this;
<svelte:head>
<title> Title here as a plain text </title>
</svelte:head>
You can use a variable if you already have pageName;
<svelte:head>
<title> {pageName} </title>
</svelte:head>
<script>
let pageName="Home";
</script>

Invalid token #end - Struts Velocity

I placed the following code in enter-protein.vm
<html>
<head>
<meta http-equiv="CONTENT-TYPE" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<h1> Enter Protein VELOCITY </h1>
#sform ("action = enter-protein")
#stextfield ("name=enteredProtein")
#ssubmit("value=Enter")
#end
<div>Amount entered: #sproperty ("value = enteredProtein")</div>
<div> Total for the day : 100 grms </div>
<div> #sproperty ("value=goalText")</div>
</body>
</head>
</html>
I get an error at #end as
Invalid token #end
I also included additional directories like commons-collections-3.2.jar, velocity-1.6.2.jar, velocity-tools-view.2.0.jar
#end marks the end of a block started by one of #if, #foreach, #macro, or #define. Neither of these is used in the rest of the template, so there's no need for the #end used in the code. Simply remove it, and the error should be gone.
Perhaps you're trying to make #sform a macro with a body? In that case, it should be called as ##sform, but that isn't supported by Velocity 1.6, which you seem to be using.

AngularJS trouble adding page titles

I am writing a web app using AngularJS. It is not a single page application but all my codes are in one file- index.ejs.
So my set up for index.ejs roughly looks like this:
<head>
<title> Main page </title>
</head>
<body>
<div class="row">
<div class="col-md-10 col-md-offset-1">
<ui-view></ui-view>
</div>
</div>
<script type = "text/ng-template" id = "/main.html">
.....
</script>
<script type = "text/ng-template" id = "/addStuff.html">
.....
</script>
<script type = "text/ng-template" id = "/searchStuff.html">
.....
</script>
<script type = "text/ng-template" id = "/about.html">
.....
</script>
</body>
I have a title for the main page on top of index.ejs. I would also like to have seperate titles for each page so when they are opened in a new tab, I know which one is which. I have tried doing:
<script type = "text/ng-template" id = "/addStuff.html">
<head>
<title> Add Stuff </title>
</head>
.....
But this doesn't work. Any ideas? Thanks.
You should use ui-router. In which case you can add a top level controller on the body or html element, for example <html ng-app="my-app" ng-controller="AppCtrl">
And add a '$stateChangeSuccess' listener whenever a new route is loaded...
.controller('AppCtrl', function AppCtrl($scope) {
$scope.$on('$stateChangeSuccess', function (event, toState, toParams, fromState, fromParams) {
if (angular.isDefined(toState.data.pageTitle)) {
$scope.pageTitle = toState.data.pageTitle;
}
});
})
Then in the route definition you can add a property called data.pageTitle
$stateProvider.state( 'profile', {
url: '/profile',
views: {
"main": {
controller: 'ProfileCtrl',
templateUrl: 'profile/profile.tpl.html'
}
},
data:{
pageTitle: 'Profile'
}
})
Then in your main index.html file, you can bind the pageTitle attribute:
<title ng-bind="pageTitle"></title>
The most important part is the you move the directive ng-app on the <html> tag if it's not already in there.
Thus all the html page is covered by angular.
Eg:
<html ng-app="app">
...
</html>
Then it's really your choice.
You can use a custom directive to wrap the title, generate a service or just use the {{ }} syntax.

Html Code in my JSP page showing error

This is my html code given below:
<td> Delete</td>
It is showing following exceptions:
Multiple annotations found at this line:
- Invalid location of tag (td).
- Invalid location of text (+) in tag
(<a>).
- Invalid location of text (+"')") in
tag (<a>).
- Undefined attribute name (jobid).
Please help me to correct it.
This works fine for me, tested here
<!DOCTYPE html>
<html>
<script>
var jobid = 23;
function confirmGo(msg,url){
alert(msg);
alert(url);
}
</script>
<body>
<td> Delete</td>
</body>
</html>

how to set HTML with head and body tags, into iframe

I need to set the HTML to iFrame. (iFrame src is null.)
e.g I get following string from web method call:
string s =
<html>
<head>
<style type="text/css"> <!-- .some dynamicaly generated css> </style>
<link id="css1" type="text/css" rel="stylesheet" href="1.css" /></head>
<body style="padding:0; margin:0;" tabIndex="-1">
--- some HTML elements ------
<script type="text/javascript">
---some script ---
</script>
</body>
</html>
I need to set this string into iFrame. But when I use iframe.innerHTML it strips out head and body tags.
Can you please help me in this? Do I need to add something to string or add some property to iframe.
Thanks in advance.
Why don't you you use jquery?, it will be more easer.
You just can var innerHtml = $( 'Your html' );
and then user function called $.html( innerHtml );