Skip to content

Commit

Permalink
Merge branch 'main' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
rogercreagh authored Sep 13, 2024
2 parents 5c69c7a + 806f369 commit d46e266
Show file tree
Hide file tree
Showing 18 changed files with 1,393 additions and 13 deletions.
22 changes: 12 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ Don't use subdirectory names which match somewhat the parent directory name. For

You won't see the effect of these when you preview the Markdown text, but you will see them by previewing the Pull Request.

[Front Matter](https://docusaurus.io/docs/next/markdown-features#front-matter) should be used for titles and position in the left-hand sidebar:
[Front Matter](https://docusaurus.io/docs/markdown-features#front-matter) should be used for titles and position in the left-hand sidebar:

```
---
Expand All @@ -106,18 +106,20 @@ sidebar-position: 2
---
```

[Code blocks](https://docusaurus.io/docs/next/markdown-features/code-blocks) are enclosed in 3 backticks, and can have a title:
```php title="hello.php"
public static function hello()
{
echo "Hello!";
}
```
[Code blocks](https://docusaurus.io/docs/markdown-features/code-blocks) are enclosed in 3 backticks, and can have a [title](https://docusaurus.io/docs/markdown-features/code-blocks#code-title)

```php title="hello.php"
public static function hello()
{
echo "Hello!";
}
```

Line numbering and highlighting of individual lines are also supported.

To aid readability of the markdown please leave a blank line before and after code blocks.

[Admonitions](https://docusaurus.io/docs/next/markdown-features/admonitions)
[Admonitions](https://docusaurus.io/docs/markdown-features/admonitions)
We don't use blank lines around content, and we add 2 spaces before the text messages.

```
Expand Down Expand Up @@ -191,4 +193,4 @@ cms-api://classes/Joomla-CMS-User-User.html
framework-api://classes/Joomla-Registry-Registry.html
```

The plugin will replace `cms-api://` or `framework-api://` with the correct URL section.
The plugin will replace `cms-api://` or `framework-api://` with the correct URL section.
103 changes: 103 additions & 0 deletions docs/building-extensions/libraries/basic-library.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
---
sidebar_position: 2
title: Create a Joomla Library
---

Creating a Joomla Library
======================================

A Joomla library is a reusable set of classes or functions that can be shared across multiple extensions. Libraries help in organizing and reusing code, making development more efficient and maintainable.

In this guide, we will create a Joomla library and learn how to use it in Joomla projects.

## Folder Structure

The folder structure for a Joomla library is as follows:

```
libraries/
yourlibraryname/
src/
YourLibrary.php
yourlibraryname.xml
```

### Key Sections of the Library

- `src/YourLibrary.php`: This is the main file of the library. It contains the class definition and the functions that the library will provide.
- `yourlibraryname.xml`: This file contains the metadata for the library.

### Extension manifest file

```xml title="libraries/yourlibraryname/yourlibraryname.xml"
<?xml version="1.0" encoding="utf-8"?>
<extension type="library" method="upgrade">
<name>Joomla 5 Example Library</name>
<libraryname>JoomlaExampleLibrary</libraryname>
<author>Author Name</author>
<creationDate>2024-09-08</creationDate>
<license>GNU General Public License version 2 or later</license>
<version>1.0.0</version>
<description>Showcase on how to create a Joomla 5 library to reuse code.</description>
<namespace path="src">VendorName\LibraryName</namespace>
<files>
<folder>src</folder>
</files>
</extension>
```

### Library Class

Inside this class is where you will define the functions that the library will provide. Here is an example of a simple library class:

```php title="libraries/yourlibraryname/src/YourLibrary.php"
<?php
namespace VendorName\LibraryName;

class YourLibrary
{
public static function helloWorld()
{
return "Hello, World!";
}

public function greet($name)
{
return "Hello, " . $name . "!";
}

}
```

### Packaging the Library for Installation

Once you have created the library, you need to package it for installation. You can do this by creating a zip file with the following structure:

```
yourlibraryname.zip
├── yourlibraryname.xml
└── src/
└── YourLibrary.php
```

With the zip file created, you can install the library using the Joomla extension manager in the Administrator backend.

## Installation

1. Go to the Joomla Administrator backend.
2. Go to Extensions > Manage > Install.
3. Upload the zip file containing the library.

## Usage

To use the library in your Joomla extension, you need to include the library in your code. Here is an example of how to use the library:

```php
<?php
use VendorName\LibraryName\YourLibrary;

$library = new YourLibrary();
echo $library->greet("John");

echo YourLibrary::helloWorld();
```
9 changes: 9 additions & 0 deletions docs/building-extensions/libraries/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
sidebar_position: 3
title: Libraries
---

Libraries
=========
Libraries are sets of functions that can be accessed by other extensions. They serve to offer a collection of features that other extensions can utilize.

Loading

0 comments on commit d46e266

Please sign in to comment.