Integrating CKeditor to my symfony 2.5 - php

I download the ckeditor and would like to integrate that in my website which is built using Symfony 2.5, reading from the documentation it seems that all third party code should go inside the vendordirectory but then what? is that all? if i put all ckeditor code inside the vendor directory then what about the js files? dont they go inside a view? I have been searching online for a solution to this and most of them seem to be pointing towards using a bundle available online which i would like to avoid and leave that as my last resort.
I have used ckeditor before with custom php and this is my first time with symfony framework, I know we are supposed to create a textarea and assign it an id or a class but what i am looking for is steps before this, for example
1) Add ckeditor to vendor
2) add it to auto load or something
3) ...
I will really appreciate if someone can direct me on how to do it?

I am not sure if this is the right way to do it but this is what worked for me.
I ended up copying the ckeditor files inside bundle/Resources/public/js
Install the assets by running the command php app/console assets:install
In your twig file add the <script src="{{ asset('bundles/blog/js/ckeditor.js') }}"></script> (please make sure to change this to your bundle name)
Assign class ckeditor to your textarea field, this is how I did it {{ form_widget(form.description, { 'attr': {'class': 'ckeditor'} }) }}
and I can see the editor on my screen
If anyone else has a better idea (other than using a bundle) I would love to hear from them

Baigs answer will work, but a problem arises when you use CKEditor in different bundles, as you will be coping the whole source directory as an asset for each bundle.
Another solution is to use "egeloen/ckeditor-bundle": "~2.0", in your composer.
You can then create a ckeditor input field in your Form and reference that in your twig file.
You can also create a ckeditor element as per the CKeditor manual in your twig page directly via javascript.
<script src="/bundles/ivoryckeditor/ckeditor.js"></script>
....
<textarea id="editor1"></textarea>
...
<script>
CKEDITOR.replace('editor1');
</script>
Note that custom plugins can be pain, the plugin needs to be stored in the project web directory, but this gets deleted everytime you update composer and dump assets. My solution to this was to create a project scriptHandler which is run with composer and copies the source files into the web public directory on update.

Like mark wrote you could use IvoryCKEditorBundle
http://symfony.com/doc/master/bundles/IvoryCKEditorBundle/installation.html
Once installed, if you want to add plugins you can use the configurations like below:
ivory_ck_editor:
default_config: default
plugins:
block:
path: "/bundles/mybundle/js/ckeditor/plugins/block/"
filename: "plugin.js
.....
configs:
default:
extraPlugins: "block"
....
toolbars:
configs:
default: ["Block"]
In my case I have a Symfony bundle called MyBundle. In Resources/public/js I have my js files.
When I load the assets, my files are pushed to the web folder /bundles/mybundle/js.
In the configuration I tell the IvoryCKEditorBundle to look for a new plugin files in that folder.
After in my default configuration, I enable my new ckeditor plugin.
And in the last line I add the new plugin to the toolbar.

Related

How do you add a vendor javascript asset to a large "vendor.js" with Laravel Mix, if the asset is not available with npm?

For example, both jquery and jstree are available with npm.
Therefore, in my Laravel project I can add this to the file "webpack.mix.js":
mix.js('resources/js/app.js', 'public/js').extract(['jquery','jstree']);
When running "npm run dev" then indeed both jquery and jstree ends up in the file "public/js/vendor.js" as expected according to the documentation about Vendor Extraction (which uses "extract(['vue'])" in the example)
As far as I understand, this works because both jquery and jstree are located in "node_modules" thanks to being defined in my "package.json" (by defining "jquery": "^3.2" and "jstree": "^3.3.9")
However, how should I use Laravel Mix to put some other javascript file asset into my large generated "vendor.js" file if that other asset is not available with npm but for example I instead retrieved it with composer?
For example the file "jsvalidation.js" from laravel-jsvalidation
I added that dependency into my project with "composer.json" (by using "proengsoft/laravel-jsvalidation": "^3.0") and then ran "composer update".
Then I used "mix.copy" in "webpack.mix.js" since I have found some info about the jsvalidation and laravel-mix:
Quote: "Keep in mind to copy your files using mix, so add in webpack.mix.js file":
mix.copy('vendor/proengsoft/laravel-jsvalidation/public/js/jsvalidation.min.js', 'public/vendor/jsvalidation/js/');
(as you might notice the above linked page is for "Laravel-6-installation" but currently there seems to be no documentation for Laravel 7 which I am using, but anyway, regarding the laravel-mix stuff I am asking about it should not be depending on which version of the jsvalidation library I am using)
So I have added the above "mix.copy" row to my "webpack.mix.js" file but then what should I to get that jsvalidation file into the large "vendor.js" together with jquery and jstree?

unable to find template, after generating bundle

ok this might be a very strange thing.
it's not the first time I work a symfony project but:
I used the symfony generate:bundle command and after that I created a bundle. Lets call it "CrimeBundle".
I saw it made a folder inside the src/
It also made automatically a DefaultController and an index.html.twig file.
Now whenever I use:
return $this->render('CrimeBundle:Default:index.html.twig');
it doesn't work: I get the error:
Unable to find template "CrimeBundle:Default:index.html.twig" (looked into: /Users/admin/sites/solve/app/Resources/views, /Users/admin/sites/solve/vendor/symfony/symfony/src/Symfony/Bridge/Twig/Resources/views/Form).
however it works whenever I use the namespaced twig path like:
return $this->render('#Crime/Default/index.html.twig');
I like the first option, because on my other projects I use it too. None of them are the same version, currently I use: 3.4.1
Again the file is there, because it works with namespaced twig paths.
I can't understand why return $this->render('CrimeBundle:Default:index.html.twig'); wouldn't work as symfony generated this code.
According to this - https://symfony.com/doc/3.4/templating.html#referencing-templates-in-a-bundle
That's the only reference type the support for bundle templates
#BundleName/directory/filename.html.twig
If you go to docs for symfony 3.1 you'll see that was the last version that supported old reference
AcmeBlogBundle:Blog:index.html.twig
Maybe you can create a pull request for this file
SensioGeneratorBundle/bundle/DefaultController.php.twig

CakePHP 3.4 load jQuery to layout

I started using libraries like jQuery or Twitter Bootstrap with composer. Now I want to load the jquery.min.js from /vendor/components/jquery/ into my /src/Template/Layout/default.ctp.
How can I do that?
Because using a normal uri doesn't work:
<script type="text/javascript" src="/vendor/components/jquery/jquery.min.js"></script>
Cake doesn't interpret the file as a file. It looks for a Controller:
Error: VendorController could not be found.
How can I load the JS-file properly?
This question is perhaps a little broad, but you probably want to look into using something like Gulp or Webpack to build your assets from the Composer files to your app's webroot. These will also enable you to concatenate and minimise all your JS/CSS assets to improve performance. Although personally I'd probably use a CDN to deliver a library like jQuery as it is so commonly used on the web that you can benefit from cross-site caching.
The reason why you are getting an error like "Error: VendorController could not be found." is because Cake can't find the 'vendor' directory inside 'webroot' so is looking for a Controller instead due to the way it handles magic routes (this bit in the routes.php file $routes->fallbacks('DashedRoute');).
If you don't want to use a tool like Gulp or Webpack you could symlink the relevant files in your webroot folder, but personally I'd use my initial suggestions as these will give you many other benefits. If you do symlink just make sure you don't symlink the entire vendor directory as you don't want to expose all the code in there.
You should place all your js in /webroot/js folder. You can use it inline by using:
echo $this->Html->script('jquery.min');
this would load : <script src="/js/jquery.min.js"></script>

How to add bootstrap cdn or pure.css to a block in concrete5 version 5.6?

I want to add/link boostrap CDN to my concrete5 (v. 5.6) block. I want it to be specific to this particular block only.
I tried to search in the old documentation at
https://legacy-documentation.concrete5.org/developers
but couldn't find anything. I found something in new documentation using assets
https://www.concrete5.org/community/forums/5-7-discussion/how-exactly-do-we-use-asset-registering
but this doesn't seem to work in old version.
Thank You
As said in the legacy-docs (version 5.6.x) under Blocks / Directory Setup / Stylesheets, JavaScript and Other Assets:
The following named items will be automatically added to a page's
header, if the block in question has been added to that page:
view.css
view.js
Additionally, this behavior also applies to any files of any name
within the following directories, should they exist:
css/
js/
So the block's CSS folder (under /application or in a package) is as follows:
blocks/block_handle/css/
You can also use the addHeaderItem call from your view function in the block's controller if you wanted to do something like the CDN, keep in mind that any CSS added will be applied to the whole page unless the classes are specific to the block.

Sylius: Change design of Sylius front end

I am new to Symfony as well as Sylius. Can anyone guide me how can I change design of Sylius front end. I want to use the Kuteshop template in it?
I want to change the front end UI of the Sylius project.
What I did is:
I copied my css, js, images etc files in web directory in a separate folder with name template (template/asstes/css/, template/assets/js/ and so on). Then I created a folder app/resources/SyliusWebBundle/Views/frontend/Homepage and also I created a file app/resources/SyliusWebBundle/Views/frontend/layout.html.twig. I defined the assets and other components but no result.
My template assets was not showing up, also I was not getting any information in it.
Does it help to get some solution to me?
Thanks so much.
The path must be app/Resources/SyliusWebBundle/views/Frontend/Homepage

Categories