I'm creating web application using laravel 5. Everypage has "//" on up-left corner. What is causing this?
The app.blade.php looks like this:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Page Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
</head>
<body>
<div class="container">
<div class="jumbotron">
#yield("content")
<p>Above content generated by MVC</p>
</div>
</div>
</body>
</html>
Well it certainly isn't anything in the blade template that's doing it.
What is probably happening is that you've got somewhere in your code a line which says echo "//"; or something similar, or a rogue line of code before your <?php block starts -- maybe you were trying to comment out a block of code that includes a <?php block.
That line doesn't have to be in the template; it could be anywhere in the code; if it's run before the template is output, then you will get the kind of effect that you're reporting here.
As for where the line is and what it's doing there, that's something you'll have to work out for yourself. But you can start by searching your codebase for echo or print statements, and for //<?php.
Related
I want to create dynamic url and content like wordpress platform but I am doing something wrong. Kindly check my code:
<?php
$pages = array("story1", "story2", "story3");
?>
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>This is my page title.</title>
<link rel="canonical" href="http://www.xyz1.com/kids-english-<?php
echo $pages[1];?>.php"/>
<!-- here the url is creating but gives error 404 -->
</head>
<body>
<p>Hello, <?php echo $pages[1];?></p><br>
<?php echo $pages[2];?>
<!-- here the second url is creating but gives error 404 -->
</body>
</html>
Now I want to get the content from database and want to load somefile.php
Here starts my second problem. I create urls by foreach loop but how to load all the content to somefile.php and how will one somefile.php will handle all the different urls and different content created dynamically. I am confused here.
Your suggestions would be welcome.
Thank You.
Well.. applications like Wordpress, Shopware and so on are built on a MVC-Design scheme like every other good coded project.
You can go for frameworks like Symfony or build your own routing mechanism.
All in all it's a little bit more tricky as you did mentioned your thoughts.
I'm new to Laravel, and I'm trying to do a "modular" page for the first time. Everything was going fine, had my base layouts, which gets extended on my home page, have set up some sections/yields with no problem (content, title, etc) but one specific #yield keeps being rendered at the wrong place, I've put it inside my head file (head.blade.php), which already have another #yield for the title, but that one keeps getting rendered inside the body. I tried doing some tests, and discovered that if I put my title #yield inside <title></title> it works OK, but if I put it outside the tag it is moved to the body.
Thats a normal Laravel way of working (#yield can't be by itself, only inside a tag) or something is wrong ?
default.blade.php
<!doctype html>
<html>
<head>
#include('includes.head')
</head>
<body>
<div class="mdl-layout mdl-js-layout mdl-layout--fixed-header mdl-layout--no-desktop-drawer-button">
#include('includes.nav')
#yield('tools')
<main class="mdl-layout__content">
<div class="page-content">
#yield('content')
</div>
</main>
#include('includes.footer')
</div>
</body>
</html>
head.blade.php
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta http-equiv="cache-control" content="no-cache">
<meta name="description" content="XXXXXX">
<meta name="author" content="XXXXXXXXXXXXX">
<title>#yield('title')</title> =====> Works normally if put here
#yield('title') =====> Rendered inside the body if put that way
<!-- jQuery 3.2.1 -->
<script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>
<!-- Normalize CSS -->
<link rel="stylesheet" type="text/css" href="css/normalize.css">
<!-- Dialog Polyfill -->
<link rel="stylesheet" type="text/css" href="css/dialog-polyfill.css">
<!-- Bootstrap 3.3.7 -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
It's a normal browser behaviour. First of all you have to place all the things inside the right places. It's like you are trying eat some fat meat without fork and then crying that your hands in fat :)
You always have to define all tags that browsers expect. Title tag define that inside title of the page is located. yield('title') just means the name that you gave its for inserting there then. It looks like id in HTML.
Since you haven't described to browser what do you want to insert here it is trying to solve the problem and it's usually a placement all the things without needed tags in body (only if we are talking about omitting tags in the header).
Building fresh from Bootstrap 3.3.4. Nav dropdown works fine on pages in the root directory, but when I call the nav in the header in a directory using:
<?php
include($_SERVER['DOCUMENT_ROOT'].'/header.php');
?>
It pulls everything but the dropdown navs don't work.
Any ideas what could be causing it?
It seems you are calling only the header part of your page. The bootstrap and jquery breaks if their code is inserted in the page more than once. Hence,
make sure that you are calling the bootstrap libraries and relevant jquery libraries in right order and only once in any page.
Something like this :-
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>My Website</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Bootstrap -->
<link href="css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<!--You code -->
</body>
<!-- javascript files-->
</html>
I am new to Laravel4, so I was learning from the documentation.
It seems everything is all correct, but the extends method literally displays its code on my web browser. I don't know hwy..
This is the layout file (base.blade.php under layouts directory)
<!-- app/views/layouts/base.blade.php -->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title></title>
<!-- You can provide some default content -->
#section('head')
<link rel="stylesheet" href="style.css" />
#show
</head>
<body>
#yield('body')
</body>
</html>
and home.blade.php.
<!-- app/views/home.blade.php -->
#extends('layouts.base')
#section('body')
<h1>Hurray!</h1>
<p>We have a template!</p>
#stop
and my routing configuration is like below..
Route::get('/',
function()
{
return View::make('home');
}
);
Now when you access to the URL, it displays just a string!
#extends('layouts.base')
I have been googling for a hour or so! still could not fix it...
What's wrong with them? :(
I checked common mistakes below
possible type
incorrect path
incorrect method name
missing appending 'blade' on the file name
BUT STILL CAN'T FIND THE PROBLEM. :(
There shouldn't be any space in the template above #extends at all no comments or whitespace
Remove
<!-- app/views/home.blade.php --> from home.blade.php
home.blade.php
#extends('layouts.base')
#section('body')
<h1>Hurray!</h1>
<p>We have a template!</p>
#stop
Possibilities are that you have printed #extends('layouts.base') twice in the page. Please have a look.
I have a php file that doesn't (for now) use any php code, that holds code for the header and main menu that will be used across all pages. The CSS file has no effect, even though I've created a style class for h1. The text "TEST" shows up, but the style is not applied. How do I properly include the CSS file?
mainMenu.php
<!--This code is included within the <head> of each page, and the stylesheet for the header and main menu are included here-->
<link href="styles/headerMenu.css" ref="stylesheet" type="text/css">
<!--Header and menu code-->
<div>
<h1>TEST</h1>
</div>
index.php
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>untitled</title>
<?php include ('./includes/mainMenu.php') ?>
</head>
<body>
</body>
</html>
The CSS file is not found. Double check the link and correct it:
<link href="menu.css" rel="stylesheet" type="text/css">
^- REL not REF
Also to prevent additional problems, remove the start and end tags of <head> and <body> from the code. The way you output the HTML elements, you would create wrong HTML if you keep those tags. Remove them and your page will be valid HTML again.
index.php:
<!DOCTYPE html>
<html>
<meta charset="utf-8" />
<title>untitled</title>
<?php include ('menu.php') ?>
</html>
Valid HTML has the benefit that you can run it through a validator to spot errors early.
I think it may be because you have got your menu appearing inside your <head> tag.
The CSS needs to go inbetween the <head> and </head> but the rest needs to be inside the <body> tag
<link href="styles/headerMenu.css" rel="stylesheet" type="text/css">
This must be at <HEAD></HEAD>
<div>
<h1>TEST</h1>
</div>
This must be at <BODY></BODY>
You have to separate this file into 2 files and include them in Head and in Body..
Don't include your HTML code in HEAD part. Only include CSS and JavaScript files in HEAD section. and you need to prefix the css or images path in some php file.
E.g.
create new php file with name "conn_path.php"
<?php
define('SITE_PATH',$_SERVER['DOCUMENT_ROOT'].'siteName/');
define('SITE_HTTP_PATH','http://localhost/'siteName/');
define('CSS_PATH','http://localhost/siteName/styles/');
define('IMAGE_PATH','http://localhost/siteName/images/');
?>
And then you path will be like below:-
mainMenu.php
<?php include "conn_path.php" ?>
<link href="<?php echo CSS_PATH ;?>headerMenu.css" rel="stylesheet" type="text/css">
It will help you in whole project…
Create a template file, with your essential (and re-used) html. Also with <html>, <head> and <body> tags and anything you must have in all pages – As your stylesheets and menu.
Then add a content section with a single variable.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>untitled</title>
<link href="styles/headerMenu.css" rel="stylesheet" type="text/css">
</head>
<body>
<!--Header and menu code-->
<div>
<h1>TEST</h1>
</div>
<?php echo $page_content; ?>
</body>
</html>
This way, any page content shoud be assigned to $page_content instead of echoed.