The issue is on Symfony 5, but I guess it can be a general issue for the communication between php and css.
First, let me say that I'm not sure this kind of thing is possible, probably but I don't know for sure, so let me know if there is some libraries that you might know to handle this kind of things
Let's say I have a simple test.html page with this code.
<div class="test">Test text</div>
I simplified but of course you also have an import from a test.css
From my Symfony Controller when I will hit my /test url, I will redirect to this test.html page with a variable marginleftthat could contain a value like 100px for example purpose.
So the question is, do I have a way to dynamically load my css using the php variable ?
To be more specific, I'm not speaking about using some javascript workaround to change the css class content when I load the page. What I am looking for is directly to load my test.css using php variables.
In other words, I would like to do something like this :
.test{
margin-left : {{marginleft}}
}
My main goal here is to provide a almost full css customization of elements from a page for my users that's why I don't want to just change defaults elements with javascript.
Thanks for your assistance.
Related
sorry for the bother.
I've already searched for a while but since i'm not practical with TYPO3, either i don't understand if what i find is useful or i don't search well cause i don't know what to search. I ask sorry in advance.
I've this project to do for my university, and i've been asked to implement a form with the underline Database to registry peole who enters in the Department and ask for them to activate the card.
I only use .inc files in fileadmin/phpinclude folder to create my pages.
What i'm not able to do is to link my own css and php files.
For example i have form.inc which should use my style.css i tried to link it through the classical html way:
<link href="fileadmin/php_include/accessi/style.css" rel="stylesheet" type="text/css">
but it doesn't work , instead, if i use an "in-page" css it works.
i think i'll have the same problem with a php file.
Could anyone, please, explain what i should do?
Thank you.
Sounds a little unsual to use external php files for building forms in TYPO3. The usual way would be to write an extension or use TYPO3's own native form component.
And the usual way to include css files in TYPO3 would be to include it via typoScript: https://docs.typo3.org/typo3cms/TyposcriptReference/Setup/Page/Index.html#includecss-array
But if you want to do it in the way you described above, it sounds pretty much like the uri to your css file is wrong. Maybe it is because you are using a relative url. Checkout the DEV-Tools of your browser and see what HTML response code the call the css resource returns. In Chrome you can see that on the "network" tab. You will also see there what absolute uri the browser called and maybe you get a clue what is wrong with your uri.
Until now, I've been using the <iframe> tag to load things like headers/footers/navbars into my webpage. These cause so much hassle though and as I'm about to start building a new site I thought I'd get it sorted now.
I was thinking of having all the html code in a php file and just loading it in dynamically.. Ideally I'd like the code to become a part of the page. So it appears inline. But I also want to be able to edit one single file if I need to change one bit rather than editing the same file 100 times.
<iframe>'s did this well until recently and I don't want to use workarounds to solve my problems. Could someone please post some code I could adapt or post a link to something that tells me how to do this? Cheers
You can use PHP's include() function to include elements like headers and footers in your pages.
So:
include('header.php');
. . . will look for a file called header.php in the same directory and include it in your page. Then you just need to write this at the top of your pages.
That said, this isn't really a very good way to go about designing your site. How about looking for a content management system, that allows you to keep the design and content of your site separate?
Are PHP includes what you're looking for ? http://php.net/manual/en/function.include.php
I had a thought and wanted to pass it by my pears before I spend hrs coding this up.
I have a php include file that contains the master nav.
The master nav is made up with ID'd div's
On each page the php is included has a javascript that runs a "getbyid" and collapse the div id that contains the page link that you are on and expands an already hidden div that contains a "active/highlighted" icon/text that indicates what page you are on.
This way you have the joys of a master php nav, easy to edit and yet dynamic and user friendly.
How does this method sound to anyone else?
As I am typing this I know this will not always work if JS is disabled or not installed. Could this function be accomplished through php alone.
Thank you in advance for any ideas or additions you care to make.
Get a couple of pages working in straight HTML and JS first, identify the bit that changes between those 2 pages, and then get PHP to output that change.
IF these pages are also expected to send GET or POST calls which PHP is supposed to act upon, then it is doubly important to make sure you have got code which basically works before bringing PHP into the mix.
Also, to avoid other annoying errors make sure each ID on each page is unique.
Hope these hints from one of your peers save you a bit of sanity. :)
What you are doing can be done in php. You can get the URL of the page your are on using various server variables.
$_SERVER['REQUEST_URI'] should be particularly helpful here. But others may be helpful http://php.net/manual/en/reserved.variables.server.php
Then, when you are rendering your nav include you can use that information and just add the appropriate css in the html you are echoing.
Display:none for the div that should be collapsed and adding a class="active" to the div you want to be active.
I believe this would be more reliable than javascript and your interface will be cleaner/smoother, without the page being edited post-load.
I want to include a specific css file that should be applied to the homepage, and 6-7 other pages throughout my site.
I know I can do this via PHP, getting the URL, finding out what page, linking the css...etc, but I was wondering if there was a slick way (or any better way) using CakePHP to include the correct css file(s).
I realize I can link the CSS file from the specific views, but - then they wouldn't be in the <head>. Is there a way to link from a view and have it show up in the head?
I hope my questions make sense, and greatly appreciate any help.
I realize I can link the CSS file from
the specific views, but - then they
wouldn't be in the <head>. Is there a
way to link from a view and have it
show up in the head?
Yes, they would be in the head. See the HTML Helper documentation:
If key 'inline' is set to false in
$options parameter, the link tags are
added to the $scripts_for_layout
variable which you can print inside
the head tag of the document.
So, this snippet in your view...
$this->Html->css('my-css', null, array('inline' => false));
...will add the proper <link> element to your <head>.
Check this little tutorial out:
http://nuts-and-bolts-of-cakephp.com/2008/05/05/css-files-and-scripts_for_layout/
Basically you can use this standard view attribute $scripts_for_layout to inject CSS files based on the view. Hope this is what you're looking for. There's a few other crazy options I thought of, involving extension parsing, but it would probably be more cumbersome than just manually linking the stylesheets. I think this link describes the best solution.
You can also have different layouts, and include css in them:
http://book.cakephp.org/view/1080/Layouts#!/view/1080/Layouts
This comes handy if all the views of a model have the same css, or script.
It is not the answer for your question, but...
you can program your own injection for the layout file. The problem with $scripts_for_layout is that js and css codes are injected in the header. If you write your own implementation you can put the $scripts_for_layout var (for the js) at the end of the layout file. The cue is: separation...
I have used AJAX to successfully change the content of a web page. I can include another web page from my domain but the problem I have is making the hyperlinks to work. If the hyperlinks use relative addressing then that will not work relative to the page I am including it in so I was investigating php to parse the html tag as I read it in
I am using the following RegExp /href[\s]?=[\s\"\']+(.*?)[\"\']/im to find the href data but would like a pointer on how I can prefix a relative address.
I would like to replace a link href="./test1/page1.html"
on page http: // foo.bar.com/folder1/info1/data.html
with href="http: // foo.bar.com/folder1/info1/./test1/page1.html" then if I include the the page content of /folder1/info1/data.html in http://foo.bar.com/folder2/faraway/another.html the links on the embedded page will function correctly
I was looking at using the php preg_replace function to do that but have very quickly come unstuck. If I am barking up the wrong tree and there is a more appropriate tool or approach can someone please point me in the right direction ;-). Maybe it can all be down in Javascript?
If you're planning to do much more javascript on the page, you could use JQuery.
function make_absolute(base_path){
$("#embedded a").each(function(){
this.attr("href",
base_path + this.attr("href")
);
});
}
Replace "#embedded" with the id of your embedded page.
This is nearly certainly overkill if you're not going to use javascript for anything else, but if you're planning to make a shiny dynamic ajaxy page, you might look into it.
Bonus:
Doing ajax page loading with JQuery:
$("#embedded").load(page_you_want_to_load)
Taking ABentSpoon's response a step further, your jQuery selector can search for all anchor tags that start with a slash.
$('#embedded a[#href^=/]').each(function() {
$(this).attr('href', baseUrl + $(this).attr('href'));
});
For more help with jQuery selectors, go here.
Why donĀ“t you just use absolute paths?
You guys have certainly helped me out here, many thanks. I think the regular expression I need would be /href[\s]?=[\s\"\']\./is as ABentSpoon pointed out "If it starts with a slash, that's absolute enough for most purposes". However I guess it would be a good excersise to enable reading pages from other sites. Luckily any of the pages I may wish to do this with are on a same site, and on same server.
To pick up on Jeroen comment of just using absolute paths, that is not really an option as there are many pages on this site. Also each page would get addressed differently (DNS) depending on where it'll be accessed from... internally or externally. If you give your links an absolute path you tie ALL of them to having that site DNS name. A problem when you find this changing all too regularly, or for that matter depatments feel the need to change thir subdirectory names, but that's another story. I wish to design this feature to be a little more flexible.
I will certainly read up about jQuery. Looks interesing, it's not something I've played with yet... more learning coming up ;-)
Thanks again for taking the time guys.